Team System Developer Center > Visual Studio Team System Forums > Visual Studio Code Analysis and Code Metrics > Modifying VSConsoleOutput.xsl so that line numbers work in VS.NET
Ask a questionAsk a question
 

General DiscussionModifying VSConsoleOutput.xsl so that line numbers work in VS.NET

  • Wednesday, February 21, 2007 1:52 AMDavid Gardiner Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I run FxCop as part of my project build, and I like how the output can be turned into warnings in the Visual Studio.NET Error List window.

    The one thing that annoyed me was that even though most warnings have a line number, you couldn't double-click on the warning to jump to the offending line in the code.

    I discovered that if you edit the VSConsoleOutput.xsl file so that adds a column value, then Visual Studio can jump to the code ok. FxCop doesn't output a column value, so I just set it to "1".

    eg.
    edit the .xsl file and replace (<xsl:value-of select="@Line"/>) with (<xsl:value-of select="@Line"/>,1)

    Maybe that change could be made to the original .xsl file too.
    -dave

All Replies

  • Wednesday, February 21, 2007 3:43 AMDavid M. KeanMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks for the suggestion. Will file a bug to get this fixed.
  • Wednesday, February 21, 2007 10:16 PMDavid M. KeanMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Turns out that this is actually a bug in MSBuild, and should be fixed in the next version of the Framework. Until then, your workaround will do fine.
  • Tuesday, July 17, 2007 11:31 AMHiral Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi David,

     

    Even after replacing the VSConsoleOutput.xsl with the latest one provided by you when I execute following from the post - build event, IDE crashes and I am not able to move further.

     

    "%ProgramFiles%\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\FxCopCmd.exe" /p:"C:\MySamples\DotNetSamples\StaticCodeAnalysisSample\StaticCodeAnalysisSample\Sample.fxCop" /console

     

    The same command works fine if i execute it from command prompt. 

     

    Please suggest on how to proceed.

     

    Thanks,

    HV

  • Thursday, August 16, 2007 11:12 PMSavvyPlayer Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I can confirm this issue under VS2005 SP1 and I've actually just spent the better part of a day trying to sort it out. I'll report back my findings if I am able to resolve the issue.
  • Friday, August 17, 2007 12:18 AMSavvyPlayer Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I believe I've found the solution: In the VSConsoleOutput.xsl file, replace this "<xsl:value-of select="/FxCopReport/Localized/String[@Key='LocationNotStoredInPdb']/text()" />" with "MSBUILD" (omit the quotes).

    AND adding an extra normal carriage return (CRLF) after <xsl:text disable-output-escaping="yes">&#xD;&#xA;</xsl:text>

    So this XSLT template is now:

    <xsl:template match="Issue">
        <xsl:if test="@Path"><xsl:value-of select="@Path"/>\<xsl:value-of select="@File"/>(<xsl:value-of select="@Line"/>,1) : </xsl:if><xsl:if test="not(@Path)">MSBUILD : </xsl:if><xsl:if test="../@BreaksBuild">error </xsl:if><xsl:if test="not(../@BreaksBuild)">warning </xsl:if> : <xsl:apply-templates select=".." mode="parentMessage" /> : <xsl:value-of select="translate(normalize-space(text()),':','')" /><xsl:text disable-output-escaping="yes">&#xD;&#xA;</xsl:text>

    </xsl:template>

    My PostBuildEvent now looks like this:

    if $(ConfigurationName) == Release cmd.exe /C "\\fileserver\CodingStandards\StaticAnalysis\StandardCodeAnalysis.bat $(TargetDir) $(TargetPath)

    The contents of the batch file:
    "C:\Program Files\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\FxCopCmd.exe" /summary /iit /ruleid:-Microsoft.Design#CA1002 /ruleid:-Microsoft.Design#CA1012 /ruleid:-Microsoft.Design#CA1020 /ruleid:-Microsoft.Design#CA1014 /ruleid:-Microsoft.Design#CA1054 /ruleid:-Microsoft.Design#CA1056 /ruleid:-Microsoft.Design#CA1030 /ruleid:-Microsoft.Design#CA1003 /ruleid:-Microsoft.Globalization#CA1301 /ruleid:-Microsoft.Globalization#CA1302 /ruleid:-Microsoft.Globalization#CA1303 /ruleid:-Microsoft.Globalization#CA1304 /ruleid:-Microsoft.Globalization#CA1306 /ruleid:-Microsoft.Globalization#CA1304 /ruleid:-Microsoft.Globalization#CA1305 /ruleid:-Microsoft.Globalization#CA1300 /ruleid:-Microsoft.Maintainability#CA1500 /ruleid:-Microsoft.Naming#CA1720 /ruleid:-Microsoft.Naming#CA1709 /ruleid:-Microsoft.Naming#CA1705 /ruleid:-Microsoft.Naming#CA1706 /ruleid:-Microsoft.Performance#CA1820 /ruleid:-Microsoft.Usage#CA2201 /ruleid:-Microsoft.Usage#CA2208 /ruleid:-Wintellect.DesignRules#Wintellect2000 /ruleid:-Wintellect.DesignRules#Wintellect2005 /ruleid:/ruleid:-Wintellect.DesignRules#Wintellect2006; /consolexsl:"C:\Program Files\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\Xml\VSConsoleOutput.xsl" /directory:%1 /file:%2

    We will add this post build event to all of our projects (we are not using TFS yet so Desktop Build configuration files are not an option) to ensure consistent application of code analysis rules during release builds.

    Cheers

  • Wednesday, August 22, 2007 12:31 AMSavvyPlayer Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Ok, this has been working well for us with one exception: We have not yet determined how to prompt the IDE to recognize these messages as bona-fide FX Cop messages. The IDE populates the Error list with all various warnings, etc., but does not enable the "Show Error Help" or "Suppress Message(s)" contextual menu items.

    Is anyone here able to shed some light on this sole remaining mystery?
  • Tuesday, August 28, 2007 6:50 PMSavvyPlayer Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    *bump*