1

I have a solution with multiple projects and we use FxCop. We want to run it once the compilation requested finishes (it may be one project, a folder with several folders or the whole solution).

Is there a way of doing this? We currently do it per project but this has some drawbacks.

Ignacio Soler Garcia
  • 21,122
  • 31
  • 128
  • 207
  • 1
    Yes, see this article: https://msdn.microsoft.com/en-us/library/dn376353.aspx – Code Different Jan 21 '15 at 14:21
  • Consider to use Teamcity for this. It's overhead to run it every time on developer machines. Also look here: http://sedodream.com/2010/10/22/MSBuildExtendingTheSolutionBuild.aspx – AuthorProxy Jan 21 '15 at 14:23
  • @AuthorProxy: it is probably worse to have to request a build just to be able to fix the tons of fxcop issues you will find and repeat it after each iteration fix. We already have a build definition that disables the fxcop in case you are not interested in it. – Ignacio Soler Garcia Jan 21 '15 at 14:27
  • We use stylecop and run it manually before publish to teamcity, because most time we know when we need to retest and when we not need this. For example while changing javascript or configs, we don't whant to wait while stylecop retest clean solution. TC makes final check. And everything is ok. Furthemore you can attach it to git precommit event handler. – AuthorProxy Jan 21 '15 at 14:41

2 Answers2

2

Yes, there is a way to do it by putting a file next to your solution file with a specific naming pattern: after.{Your solution name here}.sln.targets

<!--?xml version="1.0" encoding="utf-8"?-->
<project toolsversion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <target name="AtTheStart" beforetargets="Build">
    <message text="GenerateCode target running" importance="high">
    </message>
  </target>
  <target name="AtTheEnd" aftertargets="Build">
    <message text="GenerateCode target running" importance="high">
    </message>
  </target>
</project>

But if you want to run FxCop effectively and have visualstudio installed, you can actually activate it during the build by including /p:RunCodeAnalysis=true or /p:RunCodeAnalysis=always on the call to MsBuild. This will run the configured ruleset file during the build. /p:CodeAnalysisRuleSet=PathTo.ruleset will let you specify a specific ruleset file.

The commandline will always overwrite the project's own configuration. And it will run in the most optimal way.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
1

I would put the FxCop project set (with all the dll's in all your projects) and call it after all the projects are built in VS.

Anuja Lamahewa
  • 897
  • 1
  • 11
  • 23