Optionally run StyleCop through MSBUILD

Aug 17, 2011 at 7:12 AM

Hi,

Is there a way to turn on/off the StyleCop analysis for certain builds? Due to memory issues that I've raised before, I'd like to avoid developer's having to deal with running Stylecop, but I would like them run on the build server. Similarly, I'd like to be able to run them on the nightly, long job, but not the quick per-commit job (if possible).

Unfortunately, as soon as I include the StyleCop.Targets files, the checks are run regardless.

Cheers,

Daniel B.

PS: Or, if someone knows of a way to get the Stylecop run via MSBUILD *without* compiling, then that'd be even better.

Aug 18, 2011 at 5:19 PM

There easiest way is just to add

<StyleCopEnabled Condition=" '$(StyleCopEnabled)' == '' ">false</StyleCopEnabled> to properties section in each project file along with stylecop import.

This way during usual build there will be no StyleCop, and you'll need to pass additional parameter /p:StyleCopEnabled=true during the StyleCop nightly build.

It is also possible to run StyleCop without compilation, but the bad news are that you'll need to execute each project separately, like this:

msbuild myproj.csproj /t:StyleCop /p:StyleCopEnabled=true

I'd prefer first option for myself, it's less error prone.

Aug 18, 2011 at 9:56 PM

Hi Professor,

Thanks for the response. I worked out something similar to the second option yesterday - I modified the StyleCop.Targets file to remove the on-build run of StyleCop instead of the StyleCopEnabled flag.

We run the same targets during the on-commit and the nightly builds, so I'll see what I can do in terms of conditionally setting the StyleCopEnabled value. 

Thanks again.

Cheers,

Daniel B.