program story

Visual Studio를 설치하지 않고 빌드 에이전트에서 코드 분석 (FxCop> 10) 실행

inputbox 2020. 12. 30. 08:08
반응형

Visual Studio를 설치하지 않고 빌드 에이전트에서 코드 분석 (FxCop> 10) 실행


FxCop 10 이후 Microsoft는 FxCop에 대한 별도의 설치 프로그램 배송을 중단했습니다. 공식적으로는 현재 Visual Studio 2013/2015/2017을 설치 한 후에 만 ​​코드 분석 (FxCop 12.0 / 14.0 / 15.0)을 실행할 수 있습니다. 그러나 우리는 빌드 에이전트에 Visual Studio를 설치하지 않는 것에 대해 단호합니다. 개발자 컴퓨터 등에서 얻은 것과 동기화합니다.)

그렇다면 FxCop 12.0 / 14.0 / 15.0이 빌드 에이전트에서 작동하도록하려면 어떻게하면 좋을까요? 그래도 소스 제어에 몇 가지 바이너리 및 msbuild 파일을 추가하는 것은 허용됩니다. 그렇지 않으면 : Visual Studio 2013/2015/2017 설치 프로그램을 사용하여 FxCop 항목 만 설치하는 방법이 있습니까?

참고 : Teamcity를 빌드 서버로 사용하고 있습니다.

답변

특정 환경 및 FxCop 버전에 대한 유효한 답변이 여러 개 있으므로 쉽게 액세스 할 수 있도록 여기에 연결할 수 있습니다.


대한 의 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 (874KiB)

    amd64 \ msdia120.dll (1.07MiB)

  • 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

(또한 빌드 에이전트에 설치된 .net 4.0 / 4.5 애플리케이션을 빌드하려면 적절한 Windows (7.1 / 8.1) SDK가 필요합니다)

또한 프로젝트 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>

!! 대한 의 FxCop 12.0 / VS2013 볼 이 답변을 !

Visual Studio 2015를 설치하지 않고 FxCop 14.0 실행

전제 조건 :

  • MSBuild 14.0-> Microsoft Build Tools 2015 설치
  • Visual Studio 2015 x86 용 Visual C ++ 재배포 가능 패키지 (빌드에 따라 x86 버전이 항상 필요하며 x64 재배포가 필요할 수 있습니다. 누락 된 경우 오류 메시지가 알 수없는 것일 수 있습니다 (예 :) 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을 개별적으로 복사 할 수도 있지만 지금은 어떤 것이 필요한지 모르겠습니다. 정확히 어떤 것이 누락되었는지 확인하는 것은 매우 까다 롭고 시간이 많이 걸립니다.

빌드하려는 항목에 따라 :

  • 적절한 Windows SDK (예 : Windows 10 SDK)
  • 적절한 .net SDK / 대상 (.NET Framework 4.6 SDK는 Windows 10 SDK에 포함됨)

소스 제어에 추가 할 파일

다음은 소스 제어에 추가해야하는 파일입니다. (일부 라이센스 계약을 위반할 수 있습니다.)

(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

다음과 같이 복사하십시오.

  • 전체 FxCop 설치 폴더 내용

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

  • Visual Studio 2015 C ++ redist 또는 기타 장소에서 : ( 법률 정보 참조 ) msdia140 x86 및 x64를 다음 위치에 복사합니다.

    msdia140.dll (1057KiB)

    amd64 \ msdia140.dll (1349KiB)

  • 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

또한 프로젝트 msbuild 파일 (* .csproj)을 다음과 같이 조정했습니다 (힌트 : 이전에 VS2013에서했던 방식과 약간 다릅니다. FxCop 14가 다르게 작동하기 때문이 아니라이 방법으로 fxcop을 포함 할 수 있기 때문입니다. nuget 패키지 및 .csproj로 .targets 파일 가져 오기에 대한 표준 nuget 기능 사용) :

<!-- 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에 포함 된 것입니다.

<?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>

Visual Studio를 설치하지 않고 SonarQube 분석에 FxCop 사용

SonarQube 품질 프로필에서 FxCop 규칙을 활성화 한 경우 SonarQube에는 FxCop 14.0이 필요합니다.

이 단계는 주로 @BatteryBackupUnit 의 뛰어난 답변기반으로합니다 .

  1. 빌드 머신에 Microsoft Build Tools 2015설치 합니다.

  2. 설치 의 Microsoft Visual C ++ 2015 재배포 업데이트 3 빌드 시스템에서, x86 및 x64 모두.

  3. 빌드 머신에서 다음 레지스트리 파일 (C :가 아닌 경우 드라이브 문자 업데이트)을 가져옵니다.


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. %programfiles(x86)%\Microsoft Visual Studio 12.0\Team Tools\Static Analysis ToolsFxCop 하위 디렉터리뿐만 아니라 모든 파일을 빌드 머신의 동일한 위치에 복사합니다 .

  2. %programfiles(x86)%\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis빌드 머신의 동일한 위치에 복사 합니다.

  3. 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에 설치합니다.

당신이 볼 경우 Phx.FatalError이 모든 후 - 거기에 마지막 의식 ... 복사의 vs_profiler_x64_enu.exe에서 Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Performance Tools\Setups와 빌드 컴퓨터에 설치합니다.

@BatteryBackupUnit 지침의 편차 :

  1. Static Analysis ToolsFxCop 하위 디렉터리뿐만 아니라 전체 디렉터리가 필요합니다.
  2. FxCop 아래에 Msbuild 하위 폴더를 중첩하는 대신 원래 위치에 배치해야합니다.
  3. 복사 msdia120.dllamd64\msdia140.dll의 FxCop 디렉토리에 파일은 너무 오래 재배포가 설치되어있는 비주얼 C ++ 2015로 불필요한 보인다.
  4. 프로젝트 파일 (* .csproj)에 FxCop 관련 수정 사항이 없습니다.
  5. Custom.CodeAnalysis.targets파일이 없습니다 .

Visual Studio 2017을 설치하지 않고 FxCop 15.0 실행

전제 조건 :

  • MSBuild 15.0-> Microsoft Build Tools 2017 설치 , 여기 에서도 볼 수 있습니다.
  • 비주얼 스튜디오 2017를위한 비주얼 C ++ 재배포 86 또는 여기 OR C와 비주얼 스튜디오 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을 개별적으로 복사 할 수도 있지만 지금은 어떤 것이 필요한지 모르겠습니다. 정확히 어떤 것이 누락되었는지 확인하는 것은 매우 까다 롭고 시간이 많이 걸립니다.

빌드하려는 항목에 따라 :

  • 적절한 Windows SDK (예 : Windows 10 SDK)
  • 적절한 .net SDK / 대상 (.NET Framework 4.6 SDK는 Windows 10 SDK에 포함됨)

소스 제어에 추가 할 파일

다음은 소스 제어에 추가해야하는 파일입니다. (일부 라이센스 계약을 위반할 수 있습니다.)

(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 설치 폴더 내용

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

  • Visual Studio 2017 C ++ redist (또는 VC ++ 워크로드가 설치된 경우 Visual Studio 2017 설치 : % ProgramFiles (x86) % \ Microsoft Visual Studio \ 2017 \\ VC \ Redist \ MSVC \ 14.12.25810) 또는 기타 장소 : ( 법률 정보 참조 ) msdia140 x86 및 x64 (내 버전은 14.12.25810.0)를 다음 위치에 복사합니다.

    msdia140.dll (1.12MiB)

    amd64 \ msdia140.dll (1.42MiB)

  • 에서 %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

또한 프로젝트 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:

<?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:

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


There's a very simple way for 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).

In this directory there's a file called: FxCopCmd.exe and 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).

ReferenceURL : https://stackoverflow.com/questions/21729066/running-code-analysis-fxcop-10-on-build-agent-without-installing-visual-stud

반응형