如何在构建服务器上运行.NET 4代码分析

Ole*_*nge 13 fxcop .net-4.0 build-server

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

msbuild MySolution.sln /p:RunCodeAnalysis=true
Run Code Online (Sandbox Code Playgroud)

但那失败了.

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


我收到此错误消息:

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\CodeAnalysis\Microsoft.CodeAnalysis.targets(129,9): error MSB6003: 
The specified task executable "FxCopCmd.exe" could not be run. 
Could not load file or assembly 
'Microsoft.VisualStudio.CodeAnalysis.Sdk, Version=10.0.0.0, Culture=neutral, PublicKeyToken= b03f5f7f11d50a3a' 
or one of its dependencies. 
The system cannot find the file specified.

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

HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\10.0\Setup\EDev@FxCopDir
Run Code Online (Sandbox Code Playgroud)

Gid*_*sey 17

我在MSBuild服务器上遇到了同样的问题并修复了:

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

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

  • 文件夹规则集(默认安装目标位于: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构建的一部分运行,并使其正常工作.

  • 如果它适用于.NET 4.5的用户和VS 2012中内置的项目,你能分享一步一步的指示吗? (4认同)