2

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?

BIBD
  • 14,789
  • 24
  • 82
  • 131
Jader Dias
  • 84,588
  • 150
  • 415
  • 615

2 Answers2

2

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>
Bret Walker
  • 1,756
  • 5
  • 18
  • 40
  • It worked! Now I realize why people usually don't do this. It's slower than style cop. Maybe I should run it at each commit instead of each build. – Jader Dias Feb 09 '09 at 13:06
  • Question: It worked because of MSBuild Community Tasks, or your solution would work alone? – Jader Dias Feb 09 '09 at 13:08
2

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.

Julien Hoarau
  • 47,315
  • 20
  • 124
  • 117