locked
Running FxCop through code RRS feed

  • Question

  • Is it possible to run FxCop from code? Can I create a class to run an analysis on an assembly and then analyze the report output within my class? I'm asking because the company I'm with wants to incorporate FxCop into its build process and would like the build to fail if FxCop finds certain rules broken.

    Thanks!
    Wednesday, August 24, 2005 2:42 PM

Answers

  • This is not a supported scenario. We've experimented with this in the past and discovered there are non-trivial problems attempting to invoke FxCop analysis programmatically. Also, we intend to alter this object model substantially in the next release of FxCop (1.34), which will have a focus on performance. We will be making some fairly radical changes to reduce working set and part of this work will involve tossing out or changing most of the existing common API used by the command-line version of the tool and the UI.

    To answer your original question, though, we recommend using the command-line version of the tool. Create a project file with the appropriate rules enabled. Run the project against your analysis targets in order to create a baseline. Set the project options to only persist new messages to the output report. Create a script that invokes this project using FxCopCmd.exe. If there's any output at all (indicating a new message has appeared), fail the test.

    You can consult the FxCop help file for some general information on accomplishing the above.

    Michael Fanning
    VSTS Development: Code Analysis
    Wednesday, August 24, 2005 3:02 PM
  • Unfortunately, our integration with the VS IDE has slowed down progress in this area, and providing an extensibility mechanism for UI is not as high priority as other critical work items (such as simply documenting a stable API for writing rules themselves). We do hope to make progress here in a future version of the tool but that will likely depend on replacing our current UI entirely.
    Tuesday, October 25, 2005 5:26 PM

All replies

  • This is not a supported scenario. We've experimented with this in the past and discovered there are non-trivial problems attempting to invoke FxCop analysis programmatically. Also, we intend to alter this object model substantially in the next release of FxCop (1.34), which will have a focus on performance. We will be making some fairly radical changes to reduce working set and part of this work will involve tossing out or changing most of the existing common API used by the command-line version of the tool and the UI.

    To answer your original question, though, we recommend using the command-line version of the tool. Create a project file with the appropriate rules enabled. Run the project against your analysis targets in order to create a baseline. Set the project options to only persist new messages to the output report. Create a script that invokes this project using FxCopCmd.exe. If there's any output at all (indicating a new message has appeared), fail the test.

    You can consult the FxCop help file for some general information on accomplishing the above.

    Michael Fanning
    VSTS Development: Code Analysis
    Wednesday, August 24, 2005 3:02 PM
  • I figured you'd say that Smile Thanks for the response.
    Wednesday, August 24, 2005 3:19 PM
  • Is it an absolute requirement that you access FxCop programmatically? If there was sufficient support for this out there, we could consider making this more of a supported scenario.

    Currently, not even VS2005 accesses FxCop in this way... 8)

    Michael
    Wednesday, August 24, 2005 3:49 PM
  • In my scenario it would be.  I'm writing code analysis rules that give the user a very specific UI based on the results on the analysis.  it would be great to have more of an API to interface with the engine directly.  Too add my own rules, set the targets and all the options, then call the analysis, and spin through the resulting issues and call my own UI visualizations.

    Today the only way i've been able to mimick how the cmd line tool works, and call FxCopOM.Engines.Analyze() myself.  This works for now, but i'm sure i'll have the refigure how it all works once 1.34 comes out :-(
    Tuesday, October 25, 2005 3:40 PM
  • Unfortunately, our integration with the VS IDE has slowed down progress in this area, and providing an extensibility mechanism for UI is not as high priority as other critical work items (such as simply documenting a stable API for writing rules themselves). We do hope to make progress here in a future version of the tool but that will likely depend on replacing our current UI entirely.
    Tuesday, October 25, 2005 5:26 PM