对于FxCop 14.0 / VS2015 看到这个答案
在不安装 Visual Studio 2013 的情况下运行 FxCop 12.0
好的,我已经投入了 6 个小时,现在它正在工作。我已将所有必要的可执行文件、dll 和 msbuild 目标添加到源代码控制中。
这些是我必须添加到源代码控制的文件:(请考虑这可能违反某些许可协议)
(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.xsl
├Architecture-msil.dll
├CodeAnalysis.dll
├CustomDictionary.xml
├FxCopCmd.exe
├FxCopCmd.exe.config
├FxCopCommon.dll
├FxCopSdk.dll
├Microsoft.Cci.dll
├Microsoft.VisualStudio.CodeAnalysis.Common.dll
├Microsoft.VisualStudio.CodeAnalysis.DataflowModels.dll
├Microsoft.VisualStudio.CodeAnalysis.dll
├Microsoft.VisualStudio.CodeAnalysis.Interop.dll
├Microsoft.VisualStudio.CodeAnalysis.Phoenix.dll
├Microsoft.VisualStudio.CodeAnalysis.Phoenix.xml
├msdia120.dll
├mssp7en.dll
├mssp7en.lex
├phx.dll
└Runtime-vccrt-win-msil.dll
复制它们如下:
整个 FxCop 安装文件夹内容来自
%programfiles(x86)%\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\FxCop
从 Visual Studio 2013 C++ redist 或任何其他地方:(另请参阅法律信息)将 msdia120 x86 和 x64 复制到:
msdia120.dll (874 KiB)
amd64\msdia120.dll (1.07 MiB)
从安装了 VS2013 的计算机的全局程序集缓存 ( C:\Windows\Microsoft.NET\assembly\GAC_MSIL\_NameOfTheAssembly_\
) 中,将以下 DLL 复制到:(确保 DLL 是 12.0 版!)
Msbuild\Microsoft.VisualStudio.CodeAnalysis.dll
Msbuild\Microsoft.VisualStudio.CodeAnalysis.Sdk.dll
所有文件从%programfiles(x86)%\MSBuild\Microsoft\VisualStudio\v12.0\CodeAnalysis
到
Msbuild\fxcoptask.dll
Msbuild\Microsoft.CodeAnalysis.Targets
(此外,您需要适当的 Windows (7.1 / 8.1) SDK 来构建安装在构建代理上的 .net 4.0 / 4.5 应用程序)
此外,我们必须调整项目 msbuild 文件,如下所示:
<!--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"/>
这就是我们的 Custom.CodeAnalysis.targets 包含的内容:
<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>