Microsoft 代码合同和 CI 构建服务器

Microsoft Code Contracts and CI build server(Microsoft 代码合同和 CI 构建服务器)

本文介绍了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:

  1. Can I use code contract rewriting without installing VS on CI build Server (TeamCity)?
  2. Is there any msbuild tasks to execute Contract checking?
  3. 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:

  1. 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.

  2. 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.

  3. 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.

  4. 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 构建服务器

基础教程推荐