代码合约尝试获取构建错误而不是警告
我试图让 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来微软现在已经选择不让这成为可能,但他们正在为未来考虑:
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
问题在于代码合约使用了重写器。它们显示为警告,因为它们仅在构建完成后计算。
好吧,我真的不知道它是如何工作的,但是除非你将代码契约构建到编译器中,否则我不知道它们除了警告/消息之外还有什么。
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.