Code Contracts trying to get build errors instead of warnings

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?


看起来在这一点上,微软已经选择不要这样做,但他们正在考虑未来:http://connect.microsoft.com/VisualStudio/feedback/details/646880/code-contracts-dont-listen-以诚待人的警告-AS-错误设定


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.

链接地址: http://www.djcxy.com/p/4062.html

上一篇: 如何删除推送到远程存储库的提交?

下一篇: 代码合同试图获得构建错误而不是警告