How to run .NET 4 code analysis on build server
Asked Answered
C

3

13

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
Congo answered 19/6, 2010 at 11:31 Comment(1)
This works for C++ project, but not C# projectHyetology
P
17

I had the same problem on my MSBuild server and fixed it by:

  • Installing Windows SDK 7.1
  • Setting up the registry keys FxCopDir and StanDir in HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\10.0\Setup\EDev (in Win32).

I then copied over from the dev PC, to the FxCop folder on the build server, the following:

  • The folder Rule Sets (default installation target is here: 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

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.

Pentup answered 27/6, 2010 at 2:12 Comment(3)
Thanks! Including these assemblies and rules made it work for me.Congo
What value should be set to StanDir?Statue
if it worked for somebody with .NET 4.5 and projects built in VS 2012, could you share the step-by-step instructions?Robinson
P
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.

Pharyngology answered 19/10, 2010 at 12:25 Comment(0)
B
0

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)

Beare answered 22/6, 2010 at 7:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.