13

在带有 .NET 4 SDK 但没有 Visual Studio 2010 的 Windows Server 2003 R2 上,我尝试使用

msbuild MySolution.sln /p:RunCodeAnalysis=true

但这失败了。

在这样的环境中运行代码分析需要什么?


我收到此错误消息:

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\CodeAnalysis\Microsoft.CodeAnalysis.targets(129,9):错误 MSB6003:
无法运行指定的任务可执行文件“FxCopCmd.exe”。
无法加载文件或程序集
'Microsoft.VisualStudio.CodeAnalysis.Sdk,版本 = 10.0.0.0,文化 = 中性,PublicKeyToken = b03f5f7f11d50a3a'
或其依赖项之一。
该系统找不到指定的文件。

我已经从 SDK 安装了 FxCop,但运气不好,将变量 FxCopDir 指向了 FxCopCmd.exe 的安装位置,并将此注册表项设置为该位置:

HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\10.0\Setup\EDev@FxCopDir
4

3 回答 3

17

我在我的 MSBuild 服务器上遇到了同样的问题,并通过以下方式修复了它:

  • 安装Windows SDK 7.1
  • HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\10.0\Setup\EDev(在 Win32 中)中设置注册表项FxCopDirStanDir 。

然后我从开发 PC 复制到构建服务器上的FxCop文件夹,如下:

  • 文件夹Rule Sets(默认安装目标在这里:C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\FxCop)
  • Microsoft.VisualStudio.CodeAnalysis.Sdk.dll
  • Microsoft.VisualStudio.CodeAnalysis.Phoenix.dll
  • phx.dll

在安装了 Visual Studio 的开发 PC 上搜索它们以找到它们。

然后使用 .NET 4.0 版本的gacutil.exeMicrosoft.VisualStudio.CodeAnalysis.Sdk.dll安装到 GAC。

然后,您应该能够在 MSBuild 构建中运行代码分析并使其正常工作。

于 2010-06-27T02:12:18.503 回答
2

An alternative to FxCop would be to use the tool NDepend that lets write Code Rules over C# LINQ Queries (namely CQLinq). Disclaimer: I am one of the developers of the tool

More than 200 code rules are proposed by default. Customizing existing rules or creating your own rules is straightforward thanks to the well-known C# LINQ syntax.

Rules can be verified live in Visual Studio and at Build Process time, in a generated HTML+javascript report.

于 2010-10-19T12:25:51.527 回答
0

另一种选择可能是调用 FxCop 可执行文件作为构建任务(来自msbuildtasks),将结果保存为 XML 文件,可以在大多数 CI 工具(如 Hudson 和 CC.NET)中解析

于 2010-06-22T07:36:23.957 回答