在不安装Visual Studio的情况下在构建代理上运行代码分析(FxCop> 10) [英] Running Code Analysis (FxCop > 10) on build agent without installing Visual Studio

查看:87
本文介绍了在不安装Visual Studio的情况下在构建代理上运行代码分析(FxCop> 10)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在FxCop 10之后,Microsoft停止提供单独的FxCop安装程序. 正式安装Visual Studio 2013/2015/2017后,一个人目前只能运行代码分析(FxCop 12.0/14.0/15.0). 但是,我们坚决不将Visual Studio安装在构建代理上(然后需要与开发人员计算机上的安装保持同步安装.)

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 12.0/14.0/15.0在构建代理上运行,最好不要安装其他任何东西?不过,我接受将一些二进制文件和msbuild文件添加到源代码管理中. 否则:是否有一种方法只能使用Visual Studio 2013/2015/2017安装程序安装FxCop内容?

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?

注意:我们正在使用Teamcity作为构建服务器.

Note: we are using Teamcity as build server.

由于针对特定环境和FxCop版本有多个有效答案,因此我很乐意将它们链接到此处,以便于访问:

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 15.0 (Visual Studio 2017)
  • FxCop 14.0 (Visual Studio 2015)
  • FxCop 12.0 (Visual Studio 2013)
  • SonarQube

推荐答案

在不安装Visual Studio 2017的情况下运行FxCop 15.0

先决条件:

Run FxCop 15.0 without installing Visual Studio 2017

Prerequisites:

  • MSBuild 15.0->安装此处
  • 可重新分发给Visual Studio 2017的Visual C ++ x86 此处 OR 带有C ++的Visual Studio 2017. ---- 注意:始终需要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..除了安装整个redist之外,您还可以单独复制必要的DLL,但是目前我不知道需要哪些.要找出确切缺失的项是非常棘手且耗时的.
  • MSBuild 15.0 --> Install Microsoft Build Tools 2017, you might also want to see here
  • Visual C++ Redistributable for Visual Studio 2017 x86 or here OR Visual 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.

取决于您要构建的内容:

Depending on what you want to build:

  • 适当的Windows SDK,例如 Windows 10 SDK
  • 适当的.net SDK/目标(Windows 10 SDK中包含.NET Framework 4.6 SDK)

这些是我必须添加到源代码管理中的文件: (请考虑这可能会违反某些许可协议)

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

将它们复制如下:

  • 从以下整个FxCop安装文件夹内容

  • entire FxCop installation folder contents from

%programfiles(x86)%\Microsoft Visual Studio\2017\ **INSERT EDITION HERE** \Team Tools\Static Analysis Tools\FxCop

:%ProgramFiles(x86)%\ Microsoft Visual Studio \ 2017 \\ VC \ Redist \ MSVC \ 14.12 .25810)或其他任何地方: (另请参见法律信息)复制msdia140 x86和x64(我的版本为14.12.25810.0):

from 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)

msdia140.dll (1.12 MiB)

amd64 \ msdia140.dll(1.42 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\fxcoptask.dll

Msbuild \ Microsoft.CodeAnalysis.Targets

Msbuild\Microsoft.CodeAnalysis.Targets

Msbuild \ Microsoft.VisualStudio.CodeAnalysis.dll

Msbuild\Microsoft.VisualStudio.CodeAnalysis.dll

Msbuild \ Microsoft.VisualStudio.CodeAnalysis.Sdk.dll

Msbuild\Microsoft.VisualStudio.CodeAnalysis.Sdk.dll

此外,我还对项目msbuild文件(* .csproj)进行了如下调整:

Additionally i adjusted the project msbuild file (*.csproj) as follows:

<!-- 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"/>

这是我们的Custom.CodeAnalysis.targets包含的内容:

And this 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>..\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>

Visual Studio路径注意事项:

Visual Studio安装的路径取决于版本.它包括专业版和企业版. AFAIR社区版具有不同的路径,但也不支持FxCop.欢迎更正:-)

Notes for Visual Studio Paths:

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的情况下在构建代理上运行代码分析(FxCop&gt; 10)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆