FxCop on build (Visual Studio 2008 Professional)

2019-02-19 15:33发布

I just learned how to integrate StyleCop into Visual Studio. Now it runs every build and its errors appears as warnings. Excelent!

Now I just want to do the same thing with FxCop, but even installing MSBuild Community Tasks and adding to the proj file:

 <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>

Won't do. What else I have to do?

2条回答
ら.Afraid
2楼-- · 2019-02-19 16:02

Try putting this right before </Project> in your csproj/vbproj file:

<PropertyGroup>
    <PostBuildEvent>"%25ProgramFiles%25\Microsoft FxCop 1.36\FxCopCmd.exe" /file:"$(TargetPath)" /console /searchgac</PostBuildEvent>
</PropertyGroup>
查看更多
可以哭但决不认输i
3楼-- · 2019-02-19 16:07

For executing Fxcop after build, use the Fxcop task of MSBuildCommunityTasks in AfterBuild target:

<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>

<Target Name="AfterBuild">

  <FxCop TargetAssemblies="@(OutputAssemblies)"
         RuleLibraries="@(FxCopRuleAssemblies)" 
         DependencyDirectories="$(MSBuildCommunityTasksPath)"
         FailOnError="False"
         ApplyOutXsl="True"
         OutputXslFileName="C:\Program Files\Microsoft FxCop 1.32\Xml\FxCopReport.xsl"
         DirectOutputToConsole="true"/>

</Target>

The output will be shown in the console.

查看更多
登录 后发表回答