专注

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

StyleCop是微软的代码规范检查工具,如何将这个工具集成到CruiseControl.NET中呢?

一种方式是利用CruiseControl.NET的MSBUILD。

第一步: 新建msbuild.proj,

跟solution文件位于同个目录,它的内容如下:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
  <!-- StyleCop -->
  <UsingTask AssemblyFile="C:\Program Files (x86)\StyleCop 4.7\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>

我安装的是Stylecop4.7.11,默认安装在“C:\Program Files (x86)\StyleCop 4.7”目录下。

 

第二步,在ccnet.config文件里的StyleCop配置:

<msbuild>
       <executable>C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable>
       <workingDirectory><!—absolute path--></workingDirectory>      
       <projectFile><!—absolute path-->\msbuild.proj</projectFile>
       <buildArgs>/p:Configuration=Debug /v:diag</buildArgs>
       <priority>High</priority>
       <logger>C:\Program Files (x86)\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
       <timeout>600</timeout>
</msbuild>

posted on 2012-03-07 15:35  中金黄金  阅读(1057)  评论(0编辑  收藏  举报