Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bangsholt/11bd08144a7a0e9e3929176bcee447c0 to your computer and use it in GitHub Desktop.
Save bangsholt/11bd08144a7a0e9e3929176bcee447c0 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[
if(!Directory.Exists(Path.GetDirectoryName(PATH)))
{
Directory.CreateDirectory(Path.GetDirectoryName(PATH));
}
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment