代码合约尝试获取构建错误而不是警告

发布于 2024-10-08 07:42:19 字数 696 浏览 1 评论 0原文

我试图让 VS2010 Ultimate 与代码合同生成错误而不是警告。

我有这个简单的测试程序:

using System.Diagnostics.Contracts;

namespace MyError
{
  public class Program 
  {
     static void Main(string[] args)
     {
         Program prog = new Program();
         prog.Log(null);
     }

     public void Log(string msg)
     {
         Contract.Requires(msg != null);
     }
  }
}

它正确地确定存在违反合同的情况:

C:\...\Program.cs(10,13): warning : CodeContracts: requires is false: msg != null

在我的 csproj 文件中,有一个用于调试的属性字段:

TreatWarningsAsErrors>true

是否存在我必须在项目设置中设置其他内容才能将它们变成错误吗?

I'm trying to get VS2010 Ultimate with Code Contracts to generate Errors instead of Warnings.

I have this simple test program:

using System.Diagnostics.Contracts;

namespace MyError
{
  public class Program 
  {
     static void Main(string[] args)
     {
         Program prog = new Program();
         prog.Log(null);
     }

     public void Log(string msg)
     {
         Contract.Requires(msg != null);
     }
  }
}

It correctly determines there is a violation of the contract:

C:\...\Program.cs(10,13): warning : CodeContracts: requires is false: msg != null

In my csproj file there is this property field for Debug:

TreatWarningsAsErrors>true

Is there something else I have to set in the project settings to turn these into errors?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

手心的温暖 2024-10-15 07:42:19

看起来微软现在已经选择不让这成为可能,但他们正在为未来考虑:
http ://connect.microsoft.com/VisualStudio/feedback/details/646880/code-contracts-dont-listen-to-treat-warnings-as-errors-setting

It looks like at this point Microsoft has elected not to make this possible, but they are considering it for the future:
http://connect.microsoft.com/VisualStudio/feedback/details/646880/code-contracts-dont-listen-to-treat-warnings-as-errors-setting

街角迷惘 2024-10-15 07:42:19

问题在于代码合约使用了重写器。它们显示为警告,因为它们仅在构建完成后计算。

好吧,我真的不知道它是如何工作的,但是除非你将代码契约构建到编译器中,否则我不知道它们除了警告/消息之外还有什么。

The problem is that the code contracts use a rewriter. they show as warnings because they are only calculated after the build completes.

Well i don't really know how it works, but unless you built code contracts into the compiler i do not see how they could be anything but warnings / messages.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文