system.diagnostics.contracts.contract 存在于 v4.0 v3.5 中
我刚刚升级到 Visual Studio 2010 并安装了代码合同 msi。当我尝试使用它时,出现编译器错误,指出 v3.5 和 v4 框架中都存在 system.diagnostics.contracts.contract dll。有人知道我应该做什么来解决这个问题吗?谢谢。
I just upgraded to visual studio 2010 and installed the code contracts msi. When I try to use it I get a compiler error that the system.diagnostics.contracts.contract dll exists in both the v3.5 and v4 framework. Anyone know what I should do to resolve this? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果要将使用协定的 .NET 3.5 项目升级到 .NET 4.0,请确保删除对
Microsoft.Contracts
程序集的引用。Microsoft.Contracts
程序集提供了在 .NET 2.0 或 3.5 项目中使用的代码契约,但默认情况下随mscorlib
中的 .NET 4.0 一起提供,因此您不需要它。它们都共享 System.Diagnostics.Contracts 命名空间,因此通过同时引用两者,编译器无法确定您正在尝试使用哪一个。If you're upgrading a .NET 3.5 project that uses contracts to .NET 4.0, make sure you remove your reference to the
Microsoft.Contracts
assembly.The
Microsoft.Contracts
assembly provides code contracts for use in .NET 2.0 or 3.5 projects, but is provided by default with .NET 4.0 inmscorlib
, so you don't need it. They both share theSystem.Diagnostics.Contracts
namespace, so by having references to both at the same time, the compiler isn't able to figure out which one you're trying to use.我通过首先安装它来解决它,但你实际上并没有解决它。
然后删除了引用,然后我将项目版本更改为 4.5,之后,它就起作用了。
I solved it by first installing it, thou that did not actually solve it.
Then removed the references and then I changed the project versions to 4.5 and after that, it worked.