.net 在不安装 Visual Studio 的情况下在构建代理上运行代码分析 (FxCop > 10)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21729066/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running Code Analysis (FxCop > 10) on build agent without installing Visual Studio
提问by BatteryBackupUnit
After FxCop 10 Microsoft stopped shipping a separate installer for FxCop. Officially one can currently only run code analysis (FxCop 12.0 / 14.0 / 15.0) after installing Visual Studio 2013 / 2015 / 2017. However, we are adamant about not installing Visual Studio on the build agents (the installation needs then to be kept in-sync with what we have got on the developer computers etc.).
在 FxCop 10 之后,Microsoft 停止为 FxCop 提供单独的安装程序。官方目前只能在安装 Visual Studio 2013 / 2015 / 2017 后运行代码分析(FxCop 12.0 / 14.0 / 15.0)。但是,我们坚持不在构建代理上安装 Visual Studio(安装需要保留在-与我们在开发人员计算机等上获得的内容同步)。
So how would i go about getting FxCop 12.0 / 14.0 / 15.0 to work on a build agent, preferrably without installing anything else? I would accept adding a few binaries and msbuild files to source control, though. Otherwise: Is there a way to only install the FxCop stuff using Visual Studio 2013 / 2015 / 2017 installer?
那么我将如何让 FxCop 12.0 / 14.0 / 15.0 在构建代理上工作,最好不安装任何其他东西?不过,我会接受向源代码管理添加一些二进制文件和 msbuild 文件。否则:有没有办法只使用 Visual Studio 2013 / 2015 / 2017 安装程序安装 FxCop 的东西?
Note: we are using Teamcity as build server.
注意:我们使用 Teamcity 作为构建服务器。
Answers
答案
As there are multiple valid answers for specific environments and FxCop versions, I've taken the liberty of linking them here for easier access:
由于特定环境和 FxCop 版本有多个有效答案,我冒昧地将它们链接到此处以便于访问:
采纳答案by BatteryBackupUnit
Run FxCop 15.0 without installing Visual Studio 2017
在不安装 Visual Studio 2017 的情况下运行 FxCop 15.0
Prerequisites:
先决条件:
- MSBuild 15.0 --> Install Microsoft Build Tools 2017, you might also want to see here
- Visual C++ Redistributable for Visual Studio 2017 x86or hereORVisual Studio 2017 with C++. ---- Note: the x86 version is always required, depending on the build x64 redist may be required as well. If it is missing the error message can 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 could also copy the necessary DLLs separately, but at this point i don't know which are needed. It's quite tricky and time consuming to find out which ones are exactly missing.
- MSBuild 15.0 --> 安装Microsoft Build Tools 2017,您可能还想看这里
- Visual C++ Redistributable for Visual Studio 2017 x86or here ORVisual Studio 2017 with C++。----注意:x86 版本总是需要的,取决于构建 x64 redist 可能也需要。如果它丢失,则错误消息可能很神秘,例如
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.)。您也可以单独复制必要的 DLL,而不是安装整个 redist,但此时我不知道需要哪些。找出哪些是完全缺失的,这是非常棘手和耗时的。
Depending on what you want to build:
根据您要构建的内容:
- appropriate Windows SDK, for example Windows 10 SDK
- appropriate .net SDK / targets (.NET Framework 4.6 SDK is included in Windows 10 SDK)
- 适当的 Windows SDK,例如Windows 10 SDK
- 适当的 .net SDK / 目标(.NET Framework 4.6 SDK 包含在 Windows 10 SDK 中)
Files to Add to Source Control
要添加到源代码管理的文件
These are the files that i had to add to source control: (Please consider that this might violate some license agreements)
这些是我必须添加到源代码管理的文件:(请考虑这可能会违反某些许可协议)
(source control)\tools\FxCop15
│
├[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.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
├msdia140.dll (1057 KB)
├mssp7en.dll
├mssp7en.lex
├phx.dll
└Runtime-vccrt-win-msil.dll
Copy them as follows:
按如下方式复制它们:
entire FxCop installation folder contents from
%programfiles(x86)%\Microsoft Visual Studio\2017\ **INSERT EDITION HERE** \Team Tools\Static Analysis Tools\FxCopfrom Visual Studio 2017 C++ redist (or your Visual Studio 2017 Installation, if you've got VC++ workload installed: %ProgramFiles(x86)%\Microsoft Visual Studio\2017\\VC\Redist\MSVC\14.12.25810) or any other place: (also see legal information) copy msdia140 x86 and x64 (mine have the version 14.12.25810.0) to:
msdia140.dll (1.12 MiB)
amd64\msdia140.dll (1.42 MiB)
All files from
%programfiles(x86)%\\Microsoft Visual Studio\2017\ **INSERT EDITION HERE** \MSBuild\Microsoft\VisualStudio\v15.0\CodeAnalysistoMsbuild\fxcoptask.dll
Msbuild\Microsoft.CodeAnalysis.Targets
Msbuild\Microsoft.VisualStudio.CodeAnalysis.dll
Msbuild\Microsoft.VisualStudio.CodeAnalysis.Sdk.dll
整个 FxCop 安装文件夹内容来自
%programfiles(x86)%\Microsoft Visual Studio\2017\ **INSERT EDITION HERE** \Team Tools\Static Analysis Tools\FxCop来自 Visual Studio 2017 C++ redist(或您的 Visual Studio 2017 安装,如果您安装了 VC++ 工作负载:%ProgramFiles(x86)%\Microsoft Visual Studio\2017\\VC\Redist\MSVC\14.12.25810)或任何其他位置:(另请参阅法律信息)将 msdia140 x86 和 x64(我的版本为 14.12.25810.0)复制到:
msdia140.dll (1.12 MiB)
amd64\msdia140.dll (1.42 MiB)
从
%programfiles(x86)%\\Microsoft Visual Studio\2017\ **INSERT EDITION HERE** \MSBuild\Microsoft\VisualStudio\v15.0\CodeAnalysis到的所有文件Msbuild\fxcoptask.dll
Msbuild\Microsoft.CodeAnalysis.Targets
Msbuild\Microsoft.VisualStudio.CodeAnalysis.dll
Msbuild\Microsoft.VisualStudio.CodeAnalysis.Sdk.dll
Additionally i adjusted the project msbuild file (*.csproj) as follows:
另外我调整了项目 msbuild 文件 (*.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 this is what our Custom.CodeAnalysis.targets contains:
这就是我们的 Custom.CodeAnalysis.targets 包含的内容:
<?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>..\FxCop15\</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' OR $(RunCodeAnalysisOnce) == 'true'">
<Message Text="Text, Executing Code Analysis (FxCop) on $(MsBuildProjectName)" Importance="High" />
</Target>
</Project>
Notes for Visual Studio Paths:
Visual Studio 路径的注意事项:
The path to the visual studio installation is edition dependent. It includes Professional and Enterprise. AFAIR the community edition has a different path, but also does not support FxCop. Corrections welcome :-)
Visual Studio 安装的路径取决于版本。它包括专业版和企业版。AFAIR 社区版有不同的路径,但也不支持 FxCop。欢迎更正:-)
回答by BatteryBackupUnit
For FxCop 14.0/ VS2015 see this answer
对于FxCop 14.0/ VS2015,请参阅此答案
Run FxCop 12.0 without installing Visual Studio 2013
在不安装 Visual Studio 2013 的情况下运行 FxCop 12.0
Okay, i've invested 6 hours and now it's working. I've added all necessary executables, dlls and msbuild targets to source control.
好的,我已经投入了 6 个小时,现在它正在工作。我已将所有必要的可执行文件、dll 和 msbuild 目标添加到源代码管理中。
These are the files that i had to add to source control: (Please consider that this might 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.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
Copy them as follows:
按如下方式复制它们:
entire FxCop installation folder contents from
%programfiles(x86)%\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\FxCopfrom 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 a computer where 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\CodeAnalysistoMsbuild\fxcoptask.dll
Msbuild\Microsoft.CodeAnalysis.Targets
整个 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)
从
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\_NameOfTheAssembly_\安装了 VS2013 的计算机的全局程序集缓存 ( ) 中,将以下 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
(Furthermore you need the appropriate Windows (7.1 / 8.1) SDK for building the .net 4.0 / 4.5 application installed on the build agent)
(此外,您需要适当的 Windows (7.1 / 8.1) SDK 来构建安装在构建代理上的 .net 4.0 / 4.5 应用程序)
Additionally we had to adjust the project msbuild file as follows:
此外,我们必须按如下方式调整项目 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"/>
And this is what our Custom.CodeAnalysis.targets contains:
这就是我们的 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>
回答by BatteryBackupUnit
!! For FxCop 12.0/ VS2013 see this answer!!
!! 对于FxCop 12.0/ VS2013,请参阅此答案!
Run FxCop 14.0 without installing Visual Studio 2015
在不安装 Visual Studio 2015 的情况下运行 FxCop 14.0
Prerequisites:
先决条件:
- MSBuild 14.0 --> Install Microsoft Build Tools 2015
- Visual C++ Redistributable for Visual Studio 2015 x86(the x86 version is always required, depending on the build x64 redist may be required as well. If it is missing the error message can 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 could also copy the necessary DLLs separately, but at this point i don't know which are needed. It's quite tricky and time consuming to find out which ones are exactly missing.
- MSBuild 14.0 --> 安装Microsoft Build Tools 2015
- 适用于 Visual Studio 2015 x86 的Visual C++ Redistributable(始终需要 x86 版本,具体取决于构建 x64 redist 可能也需要。如果它丢失,错误消息可能很神秘,例如
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.)。您也可以单独复制必要的 DLL,而不是安装整个 redist,但此时我不知道需要哪些。找出哪些是完全缺失的,这是非常棘手和耗时的。
Depending on what you want to build:
根据您要构建的内容:
- appropriate Windows SDK, for example Windows 10 SDK
- appropriate .net SDK / targets (.NET Framework 4.6 SDK is included in Windows 10 SDK)
- 适当的 Windows SDK,例如Windows 10 SDK
- 适当的 .net SDK / 目标(.NET Framework 4.6 SDK 包含在 Windows 10 SDK 中)
Files to Add to Source Control
要添加到源代码管理的文件
These are the files that i had to add to source control: (Please consider that this might 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.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
├msdia140.dll (1057 KB)
├mssp7en.dll
├mssp7en.lex
├phx.dll
└Runtime-vccrt-win-msil.dll
Copy them as follows:
按如下方式复制它们:
entire FxCop installation folder contents from
%programfiles(x86)%\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\FxCopfrom 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 a computer where 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\CodeAnalysistoMsbuild\fxcoptask.dll
Msbuild\Microsoft.CodeAnalysis.Targets
整个 FxCop 安装文件夹内容来自
%programfiles(x86)%\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\FxCop从 Visual Studio 2015 C++ redist 或任何其他地方:(另请参阅法律信息)将 msdia140 x86 和 x64 复制到:
msdia140.dll (1057 KiB)
amd64\msdia140.dll (1349 KiB)
从
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\_NameOfTheAssembly_\安装了 VS2015 的计算机的全局程序集缓存 ( ),将以下 DLL 复制到:(确保 DLL 是 14.0 版!)Msbuild\Microsoft.VisualStudio.CodeAnalysis.dll
Msbuild\Microsoft.VisualStudio.CodeAnalysis.Sdk.dll
从
%programfiles(x86)%\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis到的所有文件Msbuild\fxcoptask.dll
Msbuild\Microsoft.CodeAnalysis.Targets
Additionally i adjusted the project msbuild file (*.csproj) as follows (Hint: i'm slightly deviating from the way i previously did it with VS2013. It's not because FxCop 14 works differently but rather because this way i can include fxcop by a nuget package and use standard nuget functionality for .targets file import to .csproj):
此外,我调整了项目 msbuild 文件 (*.csproj) 如下(提示:我与我之前使用 VS2013 所做的方式略有不同。这不是因为 FxCop 14 的工作方式不同,而是因为这样我可以通过nuget 包并使用标准 nuget 功能将 .targets 文件导入到 .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 this is what our Custom.CodeAnalysis.targets contains:
这就是我们的 Custom.CodeAnalysis.targets 包含的内容:
<?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>
回答by PolyTekPatrick
Using FxCop for SonarQube analysis without installing Visual Studio
在不安装 Visual Studio 的情况下使用 FxCop 进行 SonarQube 分析
If you have any FxCop rules enabled in your SonarQube quality profile, SonarQube requires FxCop 14.0.
如果您在 SonarQube 质量配置文件中启用了任何 FxCop 规则,则 SonarQube 需要 FxCop 14.0。
These steps are largely based on the outstanding answerby @BatteryBackupUnit:
这些步骤主要基于@BatteryBackupUnit的出色回答:
Install Microsoft Build Tools 2015on the build machine.
Install Microsoft Visual C++ 2015 Redistributable Update 3, both x86 and x64, on the build machine.
Import the following registry file (update drive letter if not C:) on the build machine:
在构建机器上安装Microsoft Build Tools 2015。
在构建计算机上安装Microsoft Visual C++ 2015 Redistributable Update 3(x86 和 x64)。
在构建机器上导入以下注册表文件(如果不是 C: 则更新驱动器号):
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\WDExpress.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\"
Copy all of
%programfiles(x86)%\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools(not just the FxCop subdirectory) to the same place on the build machine.Copy
%programfiles(x86)%\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysisto the same place on the build machine.From the Global Assembly Cache (C:\Windows\Microsoft.NET\assembly\GAC_MSIL_NameOfTheAssembly_) of a computer where VS2015 is installed, copy
Microsoft.VisualStudio.CodeAnalysis.dllandMicrosoft.VisualStudio.CodeAnalysis.Sdk.dll(Make sure the DLLs are version 14.0!). Either copy toC:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysison the build machine or install into the build machine's GAC.
将所有内容
%programfiles(x86)%\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools(不仅仅是 FxCop 子目录)复制到构建机器上的同一位置。复制
%programfiles(x86)%\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis到构建机器上的相同位置。从安装了 VS2015 的计算机的全局程序集缓存 (C:\Windows\Microsoft.NET\assembly\GAC_MSIL_NameOfTheAssembly_),复制
Microsoft.VisualStudio.CodeAnalysis.dll并Microsoft.VisualStudio.CodeAnalysis.Sdk.dll(确保 DLL 是 14.0 版!)。要么复制到C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis构建机器上,要么安装到构建机器的 GAC 中。
If you see Phx.FatalErrorafter all this - there's one last ritual...
Copy vs_profiler_x64_enu.exefrom Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Performance Tools\Setupsand install it on the build machine.
如果你看到Phx.FatalError这一切 - 还有最后一个仪式......vs_profiler_x64_enu.exe从Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Performance Tools\Setups构建机器上复制并安装它。
Deviations from @BatteryBackupUnit's instructions:
与@BatteryBackupUnit 说明的偏差:
- The entire
Static Analysis Toolsdirectory is needed, not just the FxCop subdirectory. - Instead of nesting a Msbuild subfolder under FxCop, you need to place it in the original location.
- Copying
msdia120.dllandamd64\msdia140.dllfiles into the FxCop directory seems unnecessary so long as the Visual C++ 2015 Redistributable is installed. - No FxCop-related modifications to the project file (*.csproj).
- No
Custom.CodeAnalysis.targetsfile.
Static Analysis Tools需要整个目录,而不仅仅是 FxCop 子目录。- 您需要将其放置在原始位置,而不是在 FxCop 下嵌套 Msbuild 子文件夹。
- 复制
msdia120.dll和amd64\msdia140.dll文件到FxCop的目录,只要在Visual C ++ 2015年可再发行安装似乎没有必要。 - 没有对项目文件 (*.csproj) 进行与 FxCop 相关的修改。
- 没有
Custom.CodeAnalysis.targets文件。
回答by samiboy
There's a very simple way for TFS:
TFS有一个非常简单的方法:
On the build machine, add an 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 dev machine).
在构建机器上,添加一个环境变量:FXCOPDIR,将其指向:(C:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\FxCop只需从您的开发机器复制此文件夹)。
In this directory there's a file called: FxCopCmd.exeand TFS Build will pick it up automatically, even if vs is not installed.
You might need to re-boot the server once or twice, but the build will eventually work.
You'll also need to ensure that two dlls are installed to the gac:
Microsoft.VisualStudio.CodeAnalysis.dll and
Microsoft.VisualStudio.CodeAnalysis.Sdk.dll
The first one can be found in the path mentioned above, but the latter, the only way i got a hold of it is that i grabbed it from the gac on my dev machine. (you can disable the special gac folder view, by modifying the registry, just google it).
在此目录中有一个名为: 的文件FxCopCmd.exe,即使未安装 vs,TFS Build 也会自动选取它。您可能需要重新启动服务器一次或两次,但构建最终会起作用。您还需要确保 gac 安装了两个 dll:Microsoft.VisualStudio.CodeAnalysis.dll 和 Microsoft.VisualStudio.CodeAnalysis.Sdk.dll 第一个可以在上面提到的路径中找到,但后者,我得到它的唯一方法是我从我的开发机器上的 gac 中获取它。(您可以禁用特殊的 gac 文件夹视图,通过修改注册表,只需 google 即可)。

