Search code examples
visual-studio-2010nugetstylecop

How do I integrate StyleCop 4.5.25 into msbuild in VS2010?


How do I setup StyleCop 4.5.25 (via NuGet package manager in VS2010) to integrate with MSBuild?

I currently have StyleCop 4.4 and the following setup: http://stylecop.codeplex.com/wikipage?title=Running%20StyleCop%20in%20VS2005%20or%20VS%20Express&referringTitle=Documentation

My goal is to switch from the current setup to using Nuget as my package manager for Stylecop while retaining the biuld integration. There are only 2 files in the package installed by Nuget(src\packages\StyleCop.4.5.25.0\lib\net35): StyleCop.dll and StyleCop.CSharp.dll. Since there is no targets file, I am not sure how to integrate this new version.


Solution

  • In your msbuild file add:

    <!--this will import stylecop as a task -->
    <UsingTask AssemblyFile="$(StyleCopInstallDirectory)Microsoft.StyleCop.dll" TaskName="StyleCopTask"/>
    
    <Target Name="RunStyleCop" >
        <StyleCopTask
            ProjectFullPath="$(MSBuildProjectFile)"
            SourceFiles="@(StyleCopFiles)"
            ForceFullAnalysis="$(StyleCopForceFullAnalysis)"
            DefineConstants="$(DefineConstants)"
            TreatErrorsAsWarnings="$(StyleCopTreatErrorsAsWarnings)"
            CacheResults="$(StyleCopCacheResults)"
            OverrideSettingsFile="$(StyleCopOverrideSettingsFile)" />
    </Target>