Skip to content

Instantly share code, notes, and snippets.

@OdaShinsuke
Created November 27, 2012 10:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save OdaShinsuke/4153608 to your computer and use it in GitHub Desktop.
Save OdaShinsuke/4153608 to your computer and use it in GitHub Desktop.
MSBuild StyleCop Output XML => Jenkins Violation Plugin
<UsingTask TaskName="ReplaceStyleCopResult" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<PATH ParameterType="System.String" Required="true" />
<WORKSPACE ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Code Type="Fragment" Language="cs"><![CDATA[
var content = File.ReadAllText(PATH);
File.WriteAllText(PATH, content.Replace(WORKSPACE, "../"));
]]></Code>
</Task>
</UsingTask>
<Target Name="OutputStyleCop">
<!-- Create a collection of files to scan -->
<CreateItem Include=".\**\*.cs">
<Output TaskParameter="Include" ItemName="StyleCopFiles" />
</CreateItem>
<StyleCopTask ProjectFullPath="$(MSBuildProjectFile)" SourceFiles="@(StyleCopFiles)" ForceFullAnalysis="true" TreatErrorsAsWarnings="true" OutputFile="result\StyleCopReport.xml" />
<ReplaceStyleCopResult PATH="result\StyleCopReport.xml" WORKSPACE="$(MSBuildProjectDirectory)" />
</Target>
@bangsholt
Copy link

I have made a small fix to create the result folder prior to copying the file into it. It can be found here:

https://gist.github.com/bangsholt/11bd08144a7a0e9e3929176bcee447c0

Thanks to OdaShinsuke for sharing in the first place :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment