locked
C/C++ static code analysis in VS2008 beta 2 RRS feed

  • Question

  • I am trying to use the static code analysis command in Visual tudio 2008 beta 2 on a C/C++ program.

     

    If I run the command with the menu (developer/code analysis) it reports back that no errors were found (even though I have inserted some very obvious errors in my project). If I run the command from the command line (as reported in the build log) and remove the /q and /ignoreinvalidtargets I get the following errors at the end of the xml output file:

     

    Code Block

     <Exceptions>

      <Exception Keyword="CA0055" Kind="AssemblyLoad">

      <Type>Microsoft.FxCop.Common.AssemblyLoadException</Type>

      <ExceptionMessage>No engine was able to load target mymfcapp.exe.</ExceptionMessage>

     </Exception>

     <Exception Keyword="CA0052" Kind="Engine">

      <Type>Microsoft.FxCop.Sdk.FxCopException</Type>

      <ExceptionMessage>No targets were selected.</ExceptionMessage>

      </Exception>

     </Exceptions>

    </FxCopReport>

     

     

    Does anyone have any idea how to get the analysis to work?

     

    Bengt

    Monday, October 8, 2007 6:47 AM

Answers

  • Is this a managed C++ project or a native one? From what you're describing it sounds like you are trying to run our managed code analysis (FxCop) against a native binary which won't work as FxCop is managed only. What you want to do is run our native code analysis (PREFast). You can enable native code analysis by going into your project properties, viewing the Code Analysis tab, and enabling "Code Analysis For C/C++" which will pass the /analyze switch to the compiler. Now when you build you should see code analysis results in your error list window.

     

    -Todd

     

     

    Monday, October 8, 2007 8:33 PM
    Moderator

All replies

  • Is this a managed C++ project or a native one? From what you're describing it sounds like you are trying to run our managed code analysis (FxCop) against a native binary which won't work as FxCop is managed only. What you want to do is run our native code analysis (PREFast). You can enable native code analysis by going into your project properties, viewing the Code Analysis tab, and enabling "Code Analysis For C/C++" which will pass the /analyze switch to the compiler. Now when you build you should see code analysis results in your error list window.

     

    -Todd

     

     

    Monday, October 8, 2007 8:33 PM
    Moderator
  • Aha. I thought the analysis for native code was divided into two steps. One with cl /analyze and then a second "prefast" step which I thought was wrapped in the fxcopcmd somehow. Am I right in assuming there is only the compiler step for native code?

     

    Thanks

    Bengt

     

    Tuesday, October 9, 2007 9:53 AM
  • Yes, cl /analyze is what we call prefast and is the only native static analysis tool that ships with Visual Studio. FxCopCmd is our managed static analysis.

     

    -Todd

    Tuesday, October 9, 2007 4:18 PM
    Moderator
  • Ok. Thank you very much for your help!

     

    Bengt

    Wednesday, October 10, 2007 6:43 AM