我可以使用 .NET 4 代码协定并保持与 .NET 3.5 兼容吗?
.NET 4 引入了代码契约作为一项新功能。我想使用 CC,但提供仍然可以在 3.5 SP1 中运行的文件。这可能吗?我可以只使用部分新功能吗?显然,CC 可以只进行静态检查而不包含在二进制文件中,这是正确的吗?
我知道 CC 可作为单独的模块用于 3.5,如果我无法使用 4 版本的 CC,这是一个可行的解决方法吗?功能集有区别吗?
.NET 4 introduced Code Contracts as a new feature. I'd like to use CC, but provide files that can still run in 3.5 SP1. Is that possible? Can I only use parts of the new functionality? Apparently it is possible to have CC only do static checks without being included in the binary files, is that correct?
I'm aware CC was available for 3.5 as separate module, is this a feasible workaround in case I can't use the 4 version of CC? Is there a difference in the feature set?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能使用 .NET 4.0 CC,但可以使用 Microsoft.Contracts.dll,它是 3.5 CC 程序集。
是的。高级版包括静态检查器,但您需要 VS2008 Team System 或 VS2010 Premium/Ultimate 才能使用 Code Contracts Premium Edition。
是的,它仍然可用。从 http://msdn.microsoft.com/en-us/devlabs 获取它/dd491992.aspx
You can't use .NET 4.0 CC but you can use Microsoft.Contracts.dll which is the 3.5 CC assembly.
Yes. The premium edition includes the static checker, but you need VS2008 Team System or VS2010 Premium/Ultimate to use Code Contracts Premium Edition.
Yes it is still available. Get it from http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx
是的,您可以将代码协定与 .NET 3.5 一起使用(但明智的做法是使用 Visual Studio 2010 进行开发,以便获得工具支持)。只需从代码合同网站下载 MSI,安装并复制将 C:\Program Files (x86)\Microsoft\Contracts\Contracts\v3.5 中的 DLL 添加到您的解决方案,并在所有项目中显式引用
Microsoft.Contracts.dll
利用它。如果您绑定的是 2010 年之前的 Visual Studio 版本,或者不支持代码协定的 2010 版本,则可以执行
ccrewrite.exe
、ccrefgen.exe< /code> 和
ccdocgen.exe
(位于C:\Program Files (x86)\Microsoft\Contracts\Bin
)作为 构建后事件。Yes, you can use Code Contracts with .NET 3.5 (but you're wise to develop with Visual Studio 2010 so you get tooling support). Just download the MSI from the Code Contracts web site, install and copy the DLLs from
C:\Program Files (x86)\Microsoft\Contracts\Contracts\v3.5
to your solution and referenceMicrosoft.Contracts.dll
explicitly in all projects that make use of it.If you're bound to an earlier version of Visual Studio than 2010, or a version of 2010 that doesn't have Code Contract support, you can execute
ccrewrite.exe
,ccrefgen.exe
andccdocgen.exe
(located inC:\Program Files (x86)\Microsoft\Contracts\Bin
) from the command line as a post build event.