没有Visual Studio的Microsoft代码合同 [英] Microsoft Code Contracts without Visual Studio

查看:112
本文介绍了没有Visual Studio的Microsoft代码合同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此堆栈溢出问题:

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

询问如何在不安装Visual Studio 2010的情况下使代码契约在构建服务器上工作.我们正在尝试做同样的事情.我们已按照接受的答案中列出的步骤进行操作,但尚未使其正常工作.

asks how to get code contracts working on a build server without installing Visual Studio 2010. We're trying to do the same. We've followed the steps outlined in the accepted answer, but haven't been able to get it working.

CodeContracts不会安装在生成服务器上.因此,按照建议,我们做了以下工作:

CodeContracts will not install on the build server unless Visual Studio is present. So following the suggestion, we've done the following:

  1. 我们从安装了Visual Studio 2010 Ultimate和Code Contracts Premium的开发计算机上复制了%programfiles%\Microsoft\Contracts\Bin的内容到构建服务器.
  2. 我们还复制了包含Microsoft.CodeContracts.targetsMicrosoft.CodeContractAnalysis.targetsMSBuild\v4.0文件夹.
  1. We copied the contents of %programfiles%\Microsoft\Contracts\Bin from a development machine with Visual Studio 2010 Ultimate and Code Contracts Premium installed to the build server.
  2. We also copied the MSBuild\v4.0 folder that contains Microsoft.CodeContracts.targets and Microsoft.CodeContractAnalysis.targets.

根据CodeContracts文档,

According to the CodeContracts documentation,

在使用通过VS用户界面启用的合同的项目或解决方案中使用msbuild时,将执行与VS中相应的构建相同的操作.

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.

这是我们的用例,我们只是在解决方案文件上调用MSBuild,如下所示.解决方案文件是通过Visual Studio创建的,其中所有预期的Code Contract选项都配置为重写.

This is our use case, we're simply calling MSBuild on our solution file as below. The solution file is created via Visual Studio with all the expected Code Contract options configured for rewriting.

<Target Name="Release">
  <MSBuild Projects = "Cofamilies\WebApplication\CofamiliesWeb.sln" Properties="Configuration=Release" />
</Target>

但是重写器没有被调用.

But the rewriter is not getting called.

有人对我们所缺少的内容提出建议和/或提出疑难解答步骤的建议吗?

Does anybody have a suggestion for what we're missing and/or suggested troubleshooting steps?

推荐答案

我在最新版本的代码合同中也遇到了同样的问题.我已经在开发PC上安装了Premium Edition,在构建服务器上安装了Standard Edition,但是由于重写器未运行,因此出现了以下错误.

I had the same problem with the latest version of Code Contracts. I had installed the Premium Edition on my development PC and the Standard Edition on the build server and was getting the following error due to the Rewriter not running.

使用时必须使用重写器 Contract.Requires< TException>

Must use the rewriter when using Contract.Requires<TException>

似乎标准版缺少MSBuild调用重写器所需的密钥文件(CodeContractsAfter.targets).

It appears that the Standard edition is missing a key file (CodeContractsAfter.targets) that is needed for MSBuild to invoke the Rewriter.

对我来说,解决方案是从 C:\ Program Files(x86)\ MSBuild \ 4.0 \ Microsoft.Common.Targets \ ImportAfter 上复制 CodeContractsAfter.targets 我的开发PC到构建服务器上的相应文件夹.

The solution for me was to copy the CodeContractsAfter.targets from C:\Program Files (x86)\MSBuild\4.0\Microsoft.Common.Targets\ImportAfter on my development PC to the corresponding folder on the build server.

注意:路径不相同,因为我的开发PC正在运行Windows 7 64位,而构建服务器正在运行Windows Server 2003 32位.因此,您需要找出环境的确切路径.

如果您不使用Premium Edition,则 CodeContractsAfter.targets 文件的内容为:

If you aren't using the Premium Edition, the contents of the CodeContractsAfter.targets file is:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!-- Begin CodeTools: CodeContracts: After -->
  <PropertyGroup>
    <CodeContractsInstallDir Condition="'$(CodeContractsInstallDir)'==''">C:\Program Files (x86)\Microsoft\Contracts\</CodeContractsInstallDir>
  </PropertyGroup>
  <Import Condition="'$(CodeContractsImported)' != 'true' AND '$(DontImportCodeContracts)' != 'true'" Project="$(CodeContractsInstallDir)MsBuild\v4.0\Microsoft.CodeContracts.targets" />

  <!-- End CodeTools: CodeContracts: After -->
</Project>

只需将以上内容粘贴到提到的 ImportAfter 文件夹中的文件中即可.

Just paste the above into a file in the folder mentioned ImportAfter folder.

这篇关于没有Visual Studio的Microsoft代码合同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆