Skip to content

CruiseControl.NET: StyleCop configuration

March 1, 2011

In this post we are going to describe StyleCop configuration for CruiseControl.NET (for 1.5 RC1 release and higher only).

Follow the steps:

1. Install StyleCop on machine where Cruise Control .NET located (actually must be you buil server).

2. Create msbuild.proj file in you MS Visual Studio project folder (where solution file is). Insert the code into created file:


 <?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">

 <!-- After DEBUG Compile -->
 StyleCop">
 </Target>
<!--more-->
 <!-- FxCop -->
 <Target Name="FxCop" />

 <!-- StyleCop -->
 <UsingTask AssemblyFile="C:\Program Files (x86)\Microsoft StyleCop 4.3.3.0\Microsoft.StyleCop.dll" TaskName="StyleCopTask"/>
 <ItemGroup>
 <!-- Add Project to Analyze with StyleCop here -->
 <Project Include="$(SolutionRoot)\**\*.csproj" />
 </ItemGroup>
 <Target Name="StyleCop">
 <Message Text="Running StyleCop..." />
 <CreateItem Include="%(Project.RootDir)%(Project.Directory)**\*.cs"
 Exclude="%(Project.RootDir)%(Project.Directory)**\*.Designer.cs">
 <Output TaskParameter="Include" ItemName="StyleCopFiles" />
 </CreateItem>
 <StyleCopTask ProjectFullPath="$(MSBuildProjectFile)"
 SourceFiles="@(StyleCopFiles)"
 AdditionalAddinPaths="@(StyleCopAdditionalAddinPaths)"
 ForceFullAnalysis="true"
 DefineConstants="DEBUG TRACE CODE_ANALYSIS"
 TreatErrorsAsWarnings="true"
 CacheResults="false"
 OverrideSettingsFile="$(SolutionRoot)\Client\Settings.StyleCop"
 OutputFile="$(CCNetWorkingDirectory)\stylecop-results.xml"
 MaxViolationCount="500">
 </StyleCopTask>
 <Message Text="StyleCop executed" />
 </Target>

</Project>

3. Insert the following code into tasks section of cc.net config file:

<!--after debug compile-->
<!--after debug compile-->
 <msbuild>
 <description>Running - After DEBUG Compile</description>
 <executable>C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</executable><!--Путь до MSBuild.exe файла-->
 <workingDirectory>C:\project1\working</workingDirectory>
 <projectFile>C:\project1\working\project1\msbuild.proj</projectFile><!--Путь до созданного нами файла. Напоминаю, он должен быть в той же папке, где располагается solution файл проекта.-->
 <buildArgs>/noconsolelogger /p:SolutionRoot=C:\_sunflower\working /v:diag</buildArgs>
 <targets>AfterDebugCompile</targets>
 <timeout>900</timeout>
 <logger>C:\Program Files (x86)\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
 </msbuild>

5. Actually that is all but we also want to visualize StyleCop results. To do it we need to modify web dashboard config file and put XSLT files for StyleCop (by default in %programs_files%)\CruiseControl.NET\webdashboard\dashboard.config):

...
<buildReportBuildPlugin>
 <xslFileNames>
 <xslFile>xsl\header.xsl</xslFile>
 <xslFile>xsl\modifications.xsl</xslFile>
 <xslFile>xsl\compile.xsl</xslFile>
 <xslFile>xsl\compile-msbuild.xsl</xslFile>
 <xslFile>xsl\MsTestSummary2008.xsl</xslFile>
 <xslFile>xsl\stylecop-summary_4_3.xsl</xslFile><!--We are addint this line-->
 </xslFileNames>
 </buildReportBuildPlugin>
...
<xslReportBuildPlugin description="MSTest 2008 Detail Report" actionName="MSTEST2008DetailReport" xslFileName="xsl\MsTestReport2008.xsl" />
<xslReportBuildPlugin description="StyleCop Report" actionName="StyleCopBuildReport" xslFileName="xsl\StyleCopReport.xsl" /><!--We are adding this line-->
...

6 . Upload and copy to server (%programs_files%\CruiseControl.NET\webdashboard\xsl\ ) the following files
StyleCopReport и StyleCopSummary

Advertisements
Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: