如何摆脱编译器错误:项目需要代码合同 [英] How to get rid of compiler error: Project requires code contracts
问题描述
我正在尝试将合同实施到现有的代码库中并且遇到问题 PDF文档第5.1.3节中给出的建议,建议将项目组和目标添加到项目文件中,以警告其他开发人员需要
CodeContracts。如果没有这个文本块(我在最后,就在< / Project>之前添加),我的代码就会编译。有了它,我收到编译错误:
I am trying to implement Contracts into an existing code base and am having problems with advice given in section 5.1.3 of the PDF documentation which advises adding a project group and target to projects files as a warning to other developers that CodeContracts are required. Without this block of text (which I add, right at the end, just before </Project>) my code compiles. With it, I receive compilation error:
错误 20 项目需要代码合同
http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx C:\vsts2010 \Cockpit Core \Dev \Source \ Cockock .Compression\Cockpit.Compression.csproj 127 5 Cockpit.Compression
Error 20 Project requires Code Contracts http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx C:\vsts2010\Cockpit Core\Dev\Source\Cockpit.Compression\Cockpit.Compression.csproj 127 5 Cockpit.Compression
我的项目定位于'.NET Framework 4',我已经下载并安装了Code Contracts 1.4.30903我开始了,为什么我会收到这些错误?并且,更有针对性的是,如何在向我的
开发者提供有用信息的同时停止获取它们?
My project is targeting '.NET Framework 4' and I downloaded and installed Code Contracts 1.4.30903 before I started, so why am I getting these errors? And, more pertinently, how can I stop getting them while still providing useful information to my fellow developers?
谢谢
推荐答案
看起来PDF文本/副本中有一个错误,它在单引号内的单词true之后插入一个空格。也就是说,当我从pdf复制时,我得到'真',有空格,而那个空格不应该在那里:'真'。
Looks like there is a bug in the PDF text/copy which inserts a space after the word true inside the single quotes. Ie., when I copy from pdf, I get 'true ', with the space, whereas that space should not be there: 'true'.
如果删除那个空格,它就有效。
If you remove that space, it works.
这是它应该是什么:
<PropertyGroup>
<CompileDependsOn>
(CompileDependsOn); CheckForCodeContracts < / CompileDependsOn >
< / < span style ="color:#A31515;"> PropertyGroup >
< 目标 名称 = " CheckForCodeContracts "
条件 = " '
(CompileDependsOn);CheckForCodeContracts</CompileDependsOn> </PropertyGroup> <Target Name="CheckForCodeContracts" Condition="'
(CodeContractsImported)'!='true' " >
< 错误 文字 = " 项目需要代码合约http://msdn.microsoft.com/en-us/devlabs/ dd491992.aspx " />
< / 目标 >
(CodeContractsImported)' != 'true'"> <Error Text="Project requires Code Contracts http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx"/> </Target>
这篇关于如何摆脱编译器错误:项目需要代码合同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!