问题描述
我刚刚安装了新发布的 Visual Studio 2017 Enterprise (RC).我无法让它与 但是,代码合同.我在 Visual Studio 2015 中使用代码合同没有任何问题.我错过了什么吗?
正如其他人所指出的,微软没有优先考虑代码合同及其 长期支持仍不清楚(尽管已经有一些通过 Roslyn 持续讨论语言级集成.
然而,截至 2017 年 3 月 11 日,社区贡献者 Yaakov 至少更新了 源代码 包含 Visual Studio 2017 构建目标a>(谢谢!).此版本支持编译期间的静态检查,以及使用 CCRewrite
的运行时验证.
注意:此版本不通过 项目的属性窗格.因此,需要通过手动将适当的属性添加到 csproj
文件来配置代码协定.全面的属性列表,请参阅下面@crimbo 的答案.
不幸的是,虽然这些更新已合并到主代码分支中,但它们都没有反映在 Marketplace 分发 或官方 NuGet 包.因此,您需要从存储库中下载并编译 源代码(这很简单;只需使用提供的 BuildCC.bat
文件).
重要提示:代码契约的静态分析对 .NET 3.5 有硬编码依赖,在任一 Windows 10 中都不再默认安装 或 Visual Studio 2017.因此,您需要确保启用此功能"(或 单独下载);否则,你会得到一个编译时错误.
或者,从 2017 年 6 月 15 日 开始,之后更新2018 年 2 月 6 日 — 贡献者 Igor Bek 将此更新包含在他的 NuGet Package,所以最简单的方法是将 CodeContracts.MSBuild
添加到您的 packages.config
通过:
Install-Package CodeContracts.MSBuild -Version 1.12.0
<块引用>
背景:Igor Bek先把这个包放在一起作为Code Contracts 团队的概念验证,后来成为官方 NuGet 包(在 v1.10.10126.2 中).由于微软还没有更新官方的 NuGet 包,所以他现在是最新的.
鉴于当前的支持状态,我不鼓励人们为新项目采用代码契约,但这应该为已经投资于现有 .NET Framework 项目的代码契约的开发人员提供向后兼容性.
I just installed the newly released Visual Studio 2017 Enterprise (RC). I'm having trouble getting it to work with Code Contracts, however. I have no problem using Code Contracts with Visual Studio 2015. Am I missing something?
As others have noted, Microsoft hasn't prioritized Code Contracts and its long-term support remains unclear (though there has been some ongoing discussion about language-level integration via Roslyn).
As of March 11th, 2017, however, community contributor Yaakov has, at least, updated the source code to include the Visual Studio 2017 build targets (thank you!). This version provides support for both static checking during compilation, as well as run-time validation using CCRewrite
.
Note: This build does not provide configuration support via the project's properties pane. As such, code contracts will need to be configured by manually adding the appropriate properties to the
csproj
file. See @crimbo's answer below for a comprehensive list of properties.
Unfortunately, while these updates have been merged into the master code branch, they are neither reflected in Marketplace distribution or the official NuGet Package. As such, you need to download and compile the source code from the repository (which is easy; just use the supplied BuildCC.bat
file).
Important: The static analysis for Code Contracts has a hard-coded dependency on .NET 3.5, which is no longer installed by default in either Windows 10 or Visual Studio 2017. As such, you'll want to ensure this "feature" is enabled (or download it separately); otherwise, you'll get a compile-time error.
Alternatively, as of June 15th, 2017—and later updated on February 6th, 2018—contributor Igor Bek has included this update in his NuGet Package, so the simplest approach is to just add CodeContracts.MSBuild
to your packages.config
via:
Install-Package CodeContracts.MSBuild -Version 1.12.0
Background: Igor Bek first put this package together as a proof-of-concept for the Code Contracts team, and it was later the basis for the official NuGet package (in v1.10.10126.2). Since Microsoft hasn't updated the official NuGet package, his is now the most up-to-date.
Given the current state of support, I wouldn't encourage people to adopt Code Contracts for new projects, but this should provide backward compatibility for developers who have already invested into Code Contracts for existing .NET Framework projects.
这篇关于Visual Studio 2017 是否适用于代码合同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!