Microsoft Code Contracts and CI build server(Microsoft 代码合同和 CI 构建服务器)
问题描述
我们正在迁移到 .NET 4,并且对实现新的按合同设计功能非常感兴趣.
我们知道 一书致敬,了解命令行工具.p>
We are migrating to .NET 4 and very interested in implementing new Design By Contract capabilities.
As we know Code Contract engine requires installation of Code Contract addin
and VS Ultimate or Premium (for static checking).
Here is my questions:
- Can I use code contract rewriting without installing VS on CI build Server (TeamCity)?
- Is there any msbuild tasks to execute Contract checking?
- Do you use Code Contract's validation with CI builds?
Can I use code contract rewriting without installing VS on CI build server (TeamCity)?
Yes. Install CodeContracts on the build server. (If it refuses to install on a machine without Visual Studio, just copy the files listed below, and their dependencies, onto the build server.) Once installed, you'll find the CodeContract tools installed in %programfiles%MicrosoftContractsBin. In that directory, there are 4 executables you'll be interested in:
ccrewrite.exe - The binary rewriter. This should be executed after compilation. It turns your contracts into runtime checks or whatever you specify you want them turned into.
ccrefgen.exe - This can generate contract reference assemblies alongside your assemblies. This is useful if you're shipping dlls to be consumed by other parties.
cccheck.exe - The static checker. On the build server, you'd run this tool over your assemblies containing contracts, and it will spit out warnings and messages as it encounters potential problems.
ccdocgen.exe - This generates XML documentation from the contracts in your code. You might want to use this if you're shipping dlls with contracts for consumption by other parties, or if you just need internal docs on your code.
Is there any msbuild tasks to execute Contract checking?
Yes. There are 2 MSBuild tasks shipping with CodeContracts: in the same CodeContracts installation directory, check out the MSBuild[framework version] folder. In that directory, there are 2 files that should help you out: Microsoft.CodeContracts.targets and Microsoft.CodeContractAnalysis.targets.
According to the CodeContracts documentation,
An msbuild script extension Microsoft .Contract. targets contains the extra build actions for the runtime contract instrumentation and static verification steps. As a result of this approach, it is possible to use the same functionality when building from the command line with the msbuild command. Using msbuild on a project or solution that uses contracts enabled via the VS user interface will perform the same actions as the corresponding build under VS.
As you can see, it is possible and supported to integrate the tools into CI builds via the MSBuild targets.
Do you use Code Contract's validation with CI builds?
Assuming you mean static checking with warnings/messages, I've done this personally, but haven't done this on a big project.
I hope this helps!
Hat tip to Jon Skeet's C# In Depth book for explanation of the command line tools.
这篇关于Microsoft 代码合同和 CI 构建服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Microsoft 代码合同和 CI 构建服务器


- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 使用 rss + c# 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01