如何在构建服务器上运行 .NET 4 代码分析
在带有 .NET 4 SDK 但没有 Visual Studio 2010 的 Windows Server 2003 R2 上,我尝试构建 Visual Studio 2010 解决方案,
msbuild MySolution.sln /p:RunCodeAnalysis=true
但失败了。
在这样的环境中运行代码分析需要什么?
我收到此错误消息:
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
On a Windows Server 2003 R2 with .NET 4 SDK but without Visual Studio 2010, I have tried building a Visual Studio 2010 solution with
msbuild MySolution.sln /p:RunCodeAnalysis=true
but that fails.
What is required to run code analysis on such an environment?
I get this error message:
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.
I have installed FxCop from the SDK and without luck pointed the variable FxCopDir to the installed location of FxCopCmd.exe, and also setting this registry entry to that location:
HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\10.0\Setup\EDev@FxCopDir
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在 MSBuild 服务器上遇到了同样的问题,并通过以下方式修复了该问题:
然后,我将以下内容从开发 PC 复制到构建服务器上的 FxCop 文件夹:
在安装了 Visual Studio 的开发 PC 上搜索它们以找到它们。
然后使用 .NET 4.0 版本的 gacutil.exe 将 Microsoft.VisualStudio.CodeAnalysis.Sdk.dll 安装到 GAC。
然后,您应该能够将代码分析作为 MSBuild 构建的一部分运行并使其正常工作。
I had the same problem on my MSBuild server and fixed it by:
I then copied over from the dev PC, to the FxCop folder on the build server, the following:
Do a search for them on your dev PC with Visual Studio installed to locate them.
Then use the .NET 4.0 version of gacutil.exe to install Microsoft.VisualStudio.CodeAnalysis.Sdk.dll to the GAC.
You should then be able to run code analysis as part of an MSBuild build and have it work properly.
FxCop 的替代方法是使用 NDepend 工具,该工具让您可以通过 C# LINQ 查询(即 CQLinq)编写代码规则)。 免责声明:我是该工具的开发人员之一
超过200条代码规则 是默认建议的。借助众所周知的 C# LINQ 语法,自定义现有规则或创建自己的规则非常简单。
可以在 Visual Studio 中实时验证规则,并在构建过程中在 生成的 HTML+javascript 报告。
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.
另一种选择可能是将 FxCop 可执行文件作为构建任务调用(来自 msbuildtasks),将结果保存为 XML 文件可以在大多数 CI 工具(例如 Hudson 和 CC.NET)中进行解析
Another option might be calling FxCop executable as a build task (from msbuildtasks), saving the result as an XML file that can be parsed within most of the CI tools (like Hudson and CC.NET)