Analysis of the execution code (FxCop 12.0 / 14.0) in the build agent without installing Visual Studio 2013/2015

After FxCop 10 Microsoft stopped delivering a separate installer for FxCop. Officially, only code analysis (FxCop 12.0 / 14.0) can be performed after installing Visual Studio 2013/2015. Nevertheless, we categorically declare that we do not install Visual Studio in the assembly agents (it is necessary that the installation is synchronized with what we received on the development computers, etc.).

So, how could I get FxCop 12.0 / 14.0 to work with the build agent, preferably without installing anything else? However, I would agree to add some binaries and msbuild files to the original control. Otherwise: is there a way to install FxCop material using the Visual Studio 2013/2015 installer?

Note: we use Teamcity as a build server.

+53
continuous-integration msbuild fxcop build-server
Feb 12 '14 at 13:17
source share
4 answers

!! For FxCop 12.0 / VS2013 see this answer !!

Launch FxCop 14.0 without installing Visual Studio 2015

Prerequisites:

  • MSBuild 14.0 → Install Microsoft Build Tools 2015
  • Visual C ++ Redistributable for Visual Studio 2015 x86 ( x86 version is always required, depending on the assembly. Redist x64 may also be required. If it is missing, the error message may be cryptic, for example, System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.CodeAnalysis.Interop.dll' or one of its dependencies. The specified module could not be found. ). Instead of installing the entire redist, you can also copy the necessary DLLs separately, but at the moment I do not know which ones are needed. This is quite complicated and takes a long time to figure out which ones are definitely missing.

Depending on what you want to build:

  • corresponding Windows SDK, e.g. Windows 10 SDK
  • corresponding .net SDK / target (SDK.NET Framework 4.6 is included in the Windows 10 SDK)

Files to add to source control

These are the files that I had to add to the original control: (Please note that this may violate some license agreements)

 (source control)\tools\FxCop14 │ ├[Engines] │ │ │ ├IntrospectionAnalysisEngine.dll │ └PhoenixAnalysisEngine.dll[Msbuild] │ │ │ ├fxcoptask.dll │ ├Microsoft.CodeAnalysis.Targets │ ├Microsoft.VisualStudio.CodeAnalysis.dll │ └Microsoft.VisualStudio.CodeAnalysis.Sdk.dll[Repository] │ │ │ ├[Compatibility] │ │ │ │ │ ├Desktop2.0.xml │ │ ├Desktop2.0SP1.xml │ │ ├Desktop2.0SP2.xml │ │ ├Desktop3.0.xml │ │ ├Desktop3.0SP1.xml │ │ ├Desktop3.0SP2.xml │ │ ├Desktop3.5.xml │ │ └Desktop3.5SP1.xml │ └system32.bin[Rules] │ │ │ ├DataflowRules.dll │ ├DesignRules.dll │ ├GlobalizationRules.dll │ ├InteroperabilityRules.dll │ ├MaintainabilityRules.dll │ ├MobilityRules.dll │ ├NamingRules.dll │ ├PerformanceRules.dll │ ├PortabilityRules.dll │ ├ReliabilityRules.dll │ ├SecurityRules.dll │ ├SecurityTransparencyRules.dll │ └UsageRules.dll[x64] │ │ │ └msdia140.dll (1349 KB) ├[Xml] │ │ │ ├CodeAnalysisReport.xsl │ ├FxCopReport.xsl │ └VSConsoleOutput.xslArchitecture-msil.dllCodeAnalysis.dllCustomDictionary.xmlFxCopCmd.exeFxCopCmd.exe.configFxCopCommon.dllFxCopSdk.dllMicrosoft.Cci.dllMicrosoft.VisualStudio.CodeAnalysis.Common.dllMicrosoft.VisualStudio.CodeAnalysis.DataflowModels.dllMicrosoft.VisualStudio.CodeAnalysis.dllMicrosoft.VisualStudio.CodeAnalysis.Interop.dllMicrosoft.VisualStudio.CodeAnalysis.Phoenix.dllMicrosoft.VisualStudio.CodeAnalysis.Phoenix.xmlmsdia140.dll (1057 KB) ├mssp7en.dllmssp7en.lexphx.dllRuntime-vccrt-win-msil.dll 

Copy them as follows:

  • full contents of the FxCop installation folder from

    %programfiles(x86)%\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\FxCop

  • from Visual Studio 2015 C ++ redist or any other place: (also see legal information ) copy msdia140 x86 and x64 to:

    msdia140.dll (1057 KiB)

    amd64 \ msdia140.dll (1349 KiB)

  • from the global assembly cache ( C:\Windows\Microsoft.NET\assembly\GAC_MSIL\_NameOfTheAssembly_\ ) of the computer on which VS2015 is installed, copy the following DLLs to: (Make sure the DLLs are version 14.0!)

    MSBuild \ Microsoft.VisualStudio.CodeAnalysis.dll

    MSBuild \ Microsoft.VisualStudio.CodeAnalysis.Sdk.dll

  • All files from %programfiles(x86)%\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis to

    Msbuild \ fxcoptask.dll

    MSBuild \ Microsoft.CodeAnalysis.Targets

In addition, I edited the project's msbuild file (* .csproj) as follows (hint: I am a little deviating from the way I used to do this with VS2013. This is not because FxCop 14 works differently, but because this way I can enable fxcop using the nuget package and use the standard nuget functions to import the .targets file into .csproj):

 <!-- Microsoft.CSharp.targets import is contained in csproj by default. This just goes to show the sequence --> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/> <!-- now this must be added --> <Import Project="$(ProjectBuildScriptDir)Custom.CodeAnalysis.targets"/> 

And here is what our Custom.CodeAnalysis.targets contains:

 <?xml version="1.0" encoding="utf-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <!-- Code analysis settings. --> <PropertyGroup> <!-- this must reference the path where you copied the FxCop stuff to --> <FxCopDir>..\FxCop14\</FxCopDir> <CodeAnalysisCulture>en-US</CodeAnalysisCulture> <CodeAnalysisRuleSet>$(SolutionDir)FxCop.ruleset</CodeAnalysisRuleSet> <!-- you can and should use another condition here. Otherwise code analysis will be run on every build in VS as well. --> <!-- in my build setup i do something like Condition=IsRunningOnTeamCity => true --> <RunCodeAnalysis>true</RunCodeAnalysis> <CodeAnalysisTreatWarningsAsErrors Condition="'$(IsRunningOnTeamCity)' != 'true'">true</CodeAnalysisTreatWarningsAsErrors> </PropertyGroup> <Import Project="$(FxCopDir)Msbuild\Microsoft.CodeAnalysis.Targets" /> <Target Name="CodeAnalysisLogHeader" BeforeTargets="RunCodeAnalysis" Condition="$(RunCodeAnalysis) == 'true'"> <Message Text="Text, Executing Code Analysis (FxCop) on $(MsBuildProjectName)" Importance="High" /> </Target> <!-- Report code analysis results to TeamCity --> <Target Name="ReportCodeAnalysisResults" AfterTargets="RunCodeAnalysis" Condition="$(RunCodeAnalysis) == 'true' AND '$(IsRunningOnTeamCity)' == 'true'"> <Message Text="##teamcity[importData type='FxCop' path='$(MSBuildProjectDirectory)\$(CodeAnalysisLogFile)']" Importance="High" /> </Target> </Project> 

Preliminary notes for FxCop 15.0 / Visual Studio 2017:

The source directories have changed a bit.

FxCop files can be copied from:

% programfiles (x86)% \ Microsoft Visual Studio \ 2017 \ INSERT PICTURE HERE \ Command Tools \ Static Analysis Tools \ FxCop

Files that need to be copied to the MSBUILD folder can be obtained from:

% programfiles (x86)% \ Microsoft Visual Studio \ 2017 \ INSERT IMAGE HERE \ MSBuild \ Microsoft \ VisualStudio \ v15.0 \ CodeAnalysis

(Edition: Professional / Enterprise. Perhaps the community, but AFAIR, has a very different path).

+35
Aug 19 '15 at 11:15
source share

!! For FxCop 14.0 / VS2015 see this answer !!

Launch FxCop 12.0 without installing Visual Studio 2013

Ok, I invested 6 hours and now it works. I added all the necessary executables, dll and msbuild to control the source code.

These are the files that I had to add to the original control: (Please note that this may violate some license agreements)

 (source control)\dev\tools\FxCop │ ├[amd64] │ │ │ └msdia120.dll[Engines] │ │ │ ├IntrospectionAnalysisEngine.dll │ └PhoenixAnalysisEngine.dll[Msbuild] │ │ │ ├fxcoptask.dll │ ├Microsoft.CodeAnalysis.Targets │ ├Microsoft.VisualStudio.CodeAnalysis.dll │ └Microsoft.VisualStudio.CodeAnalysis.Sdk.dll[Repository] │ │ │ ├[Compatibility] │ │ │ │ │ ├Desktop2.0.xml │ │ ├Desktop2.0SP1.xml │ │ ├Desktop2.0SP2.xml │ │ ├Desktop3.0.xml │ │ ├Desktop3.0SP1.xml │ │ ├Desktop3.0SP2.xml │ │ ├Desktop3.5.xml │ │ └Desktop3.5SP1.xml │ └system32.bin[Rules] │ │ │ ├DataflowRules.dll │ ├DesignRules.dll │ ├GlobalizationRules.dll │ ├InteroperabilityRules.dll │ ├MaintainabilityRules.dll │ ├MobilityRules.dll │ ├NamingRules.dll │ ├PerformanceRules.dll │ ├PortabilityRules.dll │ ├ReliabilityRules.dll │ ├SecurityRules.dll │ ├SecurityTransparencyRules.dll │ └UsageRules.dll[Xml] │ │ │ ├CodeAnalysisReport.xsl │ ├FxCopReport.xsl │ └VSConsoleOutput.xslArchitecture-msil.dllCodeAnalysis.dllCustomDictionary.xmlFxCopCmd.exeFxCopCmd.exe.configFxCopCommon.dllFxCopSdk.dllMicrosoft.Cci.dllMicrosoft.VisualStudio.CodeAnalysis.Common.dllMicrosoft.VisualStudio.CodeAnalysis.DataflowModels.dllMicrosoft.VisualStudio.CodeAnalysis.dllMicrosoft.VisualStudio.CodeAnalysis.Interop.dllMicrosoft.VisualStudio.CodeAnalysis.Phoenix.dllMicrosoft.VisualStudio.CodeAnalysis.Phoenix.xmlmsdia120.dllmssp7en.dllmssp7en.lexphx.dllRuntime-vccrt-win-msil.dll 

Copy them as follows:

  • full contents of the FxCop installation folder from

    %programfiles(x86)%\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\FxCop

  • from Visual Studio 2013 C ++ redist or any other place: (also see legal information ) copy msdia120 x86 and x64 to:

    msdia120.dll (874 KiB)

    amd64 \ msdia120.dll (1.07 MiB)

  • From the global assembly cache ( C:\Windows\Microsoft.NET\assembly\GAC_MSIL\_NameOfTheAssembly_\ ) of the computer on which VS2013 is installed, copy the following DLLs to: (Make sure the DLLs are version 12.0!)

    MSBuild \ Microsoft.VisualStudio.CodeAnalysis.dll

    MSBuild \ Microsoft.VisualStudio.CodeAnalysis.Sdk.dll

  • All files from %programfiles(x86)%\MSBuild\Microsoft\VisualStudio\v12.0\CodeAnalysis to

    Msbuild \ fxcoptask.dll

    MSBuild \ Microsoft.CodeAnalysis.Targets

(In addition, you need the appropriate Windows SDK (7.1 / 8.1) to create the .net 4.0 / 4.5 application installed in the build agent)

In addition, we had to configure the project msbuild file as follows:

 <!--Must import code analysis target before importing csharp targets, so that the correct code analysis targets gets imported. --> <Import Project="$(ProjectBuildScriptDir)Custom.CodeAnalysis.targets"/> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/> 

And here is what our Custom.CodeAnalysis.targets contains:

  <PropertyGroup> <!-- Code analysis settings. --> <CodeAnalysisCulture>en-US</CodeAnalysisCulture> <!-- change this so it points to your ruleset or remove it entirely --> <CodeAnalysisRuleSet>$(SourcesDir)Custom.ruleset</CodeAnalysisRuleSet> <!-- this must refer to the source control directory where you copied FxCopCommand.exe (and the rest of the FxCop files and directories...) to --> <CodeAnalysisPath>$(ToolsDir)FxCop\</CodeAnalysisPath> <!-- this must refer to the source control directory where you copied fxcoptask.dll, Microsoft.CodeAnalysis.Targets, Microsoft.VisualStudio.CodeaAnalysis.dll and Microsoft.VisualStudio.CodeaAnalysis.Sdk.dll to --> <CodeAnalysisTargets>$(CodeAnalysisPath)Msbuild\Microsoft.CodeAnalysis.Targets</CodeAnalysisTargets> </PropertyGroup> <!-- configure this according to your wishes --> <PropertyGroup Condition="'$(Configuration)' == 'Release'"> <CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors> <RunCodeAnalysis>true</RunCodeAnalysis> </PropertyGroup> <!-- Report code analysis results to TeamCity --> <Target Name="ReportCodeAnalysisResults" AfterTargets="RunCodeAnalysis" Condition="'$(RunCodeAnalysis)' == 'true' And '$(IsRunningOnTeamCity)' == 'true'"> <Message Text="##teamcity[importData type='FxCop' path='$(CodeAnalysisLogFile)']" Importance="High" /> </Target> </Project> 
+50
Feb 12 '14 at
source share

Using FxCop to Analyze SonarQube Without Installing Visual Studio

If you have any FxCop rules included in your SonarQube quality profile, SonarQube requires FxCop 14.0.

These steps are mainly based on the outstanding answer to @BatteryBackupUnit:

 Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\WDExpress\14.0\Setup\EDev] "StanDir"="C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Team Tools\\Static Analysis Tools\\" "FxCopDir"="C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Team Tools\\Static Analysis Tools\\FxCop\\" 
  1. Copy all %programfiles(x86)%\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools (and not just the FxCop subdirectory) to the same location on the build machine.

  2. Copy %programfiles(x86)%\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis to the same location on the build machine.

  3. From the global assembly cache (C: \ Windows \ Microsoft.NET \ assembly \ GAC_MSIL_NameOfTheAssembly_) of the computer on which VS2015 is installed, copy Microsoft.VisualStudio.CodeAnalysis.dll and Microsoft.VisualStudio.CodeAnalysis.Sdk.dll (make sure the DLL version is 14.0!). Either copy it to C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis on the build machine, or install the GAC in the build machine.

Deviations from @BatteryBackupUnit instructions:

  • The entire Static Analysis Tools directory is required, not just the FxCop subdirectory.
  • Instead of embedding the Msbuild subfolder under FxCop, you need to put it in its original location.
  • Copying msdia120.dll and amd64\msdia140.dll files to the FxCop directory seems unnecessary until Redistributable Visual C ++ 2015 is installed.
  • No changes related to FxCop in the project file (* .csproj).
  • No Custom.CodeAnalysis.targets .
+8
Jun 09 '16 at 8:12
source share

There is a very simple way for TFS :

On the build machine, add the environment variable: FXCOPDIR , point it to: C:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\FxCop (just copy this folder from your machine).

There is a file in this directory called: FxCopCmd.exe and TFS Build will automatically pick it up, even if vs is not installed. You may need to restart the server once or twice, but the assembly will eventually work. You also need to make sure that two dll libraries are installed in gac: Microsoft.VisualStudio.CodeAnalysis.dll and Microsoft.VisualStudio.CodeAnalysis.Sdk.dll The first of them can be found in the above path, but the last, the only way I kept it , is that I grabbed it from gac on my dev machine. (you can disable the special view of the gac folder by changing the registry, just go to Google).

+1
Jul 29 '14 at 16:50
source share



All Articles