Getting individual logFiles for each file run in StyleCop Task

Feb 11, 2010 at 8:54 PM

Instead of sending an Itemgroup of files, so that I can run a single batch StyleCop task, I want to run it once for each file and get an output log file named "filename.txt" or something like that.

This is the code I have now, which runs it as a batch, like most people do:

    <MSBuild.ExtensionPack.CodeQuality.StyleCop TaskAction="Scan" 
SourceFiles="@(ItemsFromStyleCopList)" 
ShowOutput="true" 
ForceFullAnalysis="true" 
CacheResults="false" 
logFile="$(dirFileTest)\StyleCopLog.txt" 
SettingsFile="$(dirCheckout)\Source\CSharp\Settings.SourceAnalysis">

 

What I would rather do, is change "SourceFiles="%(ItemsFromStyleCopList.Identity)"

This should make StyleCop run one time, for each file name in the list.  What I am not sure how to do, is to make the "logFile=..." end up creating a txt file with the name of the file being tested.

Any ideas on how to do this?

Coordinator
Feb 13, 2010 at 9:49 AM

Look at well known metadata on MSDN: http://msdn.microsoft.com/en-us/library/ms164313.aspx

 

e.g.

 

<Project ToolsVersion="3.5" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <TPath>$(MSBuildProjectDirectory)\..\MSBuild.ExtensionPack.tasks</TPath>
        <TPath Condition="Exists('$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks')">$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks</TPath>
    </PropertyGroup>
    <Import Project="$(TPath)"/>
    <Target Name="Default">
        <!-- Create a collection of files to scan -->
        <CreateItem Include="C:\Demo\**\*.cs">
            <Output TaskParameter="Include" ItemName="StyleCopFiles"/>
        </CreateItem>
        <!-- Run the StyleCop MSBuild task -->
        <MSBuild.ExtensionPack.CodeQuality.StyleCop TaskAction="Scan" SourceFiles="%(StyleCopFiles.Identity)" ShowOutput="true" ForceFullAnalysis="true" CacheResults="false" logFile="C:\a\%(StyleCopFiles.FileName) - StyleCopLog.txt" SettingsFile="C:\Program Files (x86)\MSBuild\Microsoft\StyleCop\v4.3\Settings.StyleCop">
            <Output TaskParameter="Succeeded" PropertyName="AllPassed"/>
            <Output TaskParameter="ViolationCount" PropertyName="Violations"/>
            <Output TaskParameter="FailedFiles" ItemName="Failures"/>
        </MSBuild.ExtensionPack.CodeQuality.StyleCop>
        <Message Text="Succeeded: $(AllPassed), Violations: $(Violations)"/>
        <!-- FailedFile format is:
        <ItemGroup>
            <FailedFile Include="filename">
                <CheckId>SA Rule Number</CheckId>
                <RuleDescription>Rule Description</RuleDescription>
                <RuleName>Rule Name</RuleName>
                <LineNumber>Line the violation appears on</LineNumber>
                <Message>SA violation message</Message>
            </FailedFile>
        </ItemGroup>-->
        <Message Text="%(Failures.Identity) - Failed on Line %(Failures.LineNumber). %(Failures.CheckId): %(Failures.Message)"/>
    </Target>
</Project>

 

 

<Project ToolsVersion="3.5" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <PropertyGroup>

        <TPath>$(MSBuildProjectDirectory)\..\MSBuild.ExtensionPack.tasks</TPath>

        <TPath Condition="Exists('$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks')">$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks</TPath>

    </PropertyGroup>

    <Import Project="$(TPath)"/>

    <Target Name="Default">

        <!-- Create a collection of files to scan -->

        <CreateItem Include="C:\Demo\**\*.cs">

            <Output TaskParameter="Include" ItemName="StyleCopFiles"/>

        </CreateItem>

        <!-- Run the StyleCop MSBuild task -->

        <MSBuild.ExtensionPack.CodeQuality.StyleCop TaskAction="Scan" SourceFiles="%(StyleCopFiles.Identity)" ShowOutput="true" ForceFullAnalysis="true" CacheResults="false" logFile="C:\a\%(StyleCopFiles.FileName) - StyleCopLog.txt" SettingsFile="C:\Program Files (x86)\MSBuild\Microsoft\StyleCop\v4.3\Settings.StyleCop">

            <Output TaskParameter="Succeeded" PropertyName="AllPassed"/>

            <Output TaskParameter="ViolationCount" PropertyName="Violations"/>

            <Output TaskParameter="FailedFiles" ItemName="Failures"/>

        </MSBuild.ExtensionPack.CodeQuality.StyleCop>

        <Message Text="Succeeded: $(AllPassed), Violations: $(Violations)"/>

        <!-- FailedFile format is:

        <ItemGroup>

            <FailedFile Include="filename">

                <CheckId>SA Rule Number</CheckId>

                <RuleDescription>Rule Description</RuleDescription>

                <RuleName>Rule Name</RuleName>

                <LineNumber>Line the violation appears on</LineNumber>

                <Message>SA violation message</Message>

            </FailedFile>

        </ItemGroup>-->

        <Message Text="%(Failures.Identity) - Failed on Line %(Failures.LineNumber). %(Failures.CheckId): %(Failures.Message)"/>

    </Target>

</Project>

 

Feb 15, 2010 at 2:02 PM

Thank you very much.  I was thinking along these lines, but I thought putting the % sign into two different places in the same task would cause it to iterate through the item group twice.

Appreciate your response and metadata link.  It works great!