Visual Studio 2012 Express Code Analysis

2019-04-11 22:07发布

问题:

The Microsoft documentation talks about a limited set of code analysis tools being available for the express edition (e.g. Microsoft Visual Studio Blog ).

I am using VS 2012 update 3, and can not see any code analysis options in context menus, or any buttons or menu options. I am pretty sure I ran some code analysis at some point, but that might have been before update 2 was installed.

Does anyone know if this option has been removed from more recent express editions, and if not where I can find the appropriate menu item or settings to be able to run and view the results of code analysis.

Edit

there is a very clear description given below by Crippledsmurf, and it is obviously possible to access Code Analysis from vs express. I must have somehow changed some option, because none of the options described are accessible:

Solution explorer - solution context menu:

project context menu:

project properties:

回答1:

As far as I know, code analysis is only available in VS Express 2012 For Windows Desktop - if you have some other version than the "for Windows Desktop" version, it may not be supported. Try Googling your specific version to make sure.

It may be that these options are not supported by your "platform toolset" (project properties -> general -> platform toolset).

For example, v110 supports it, v110_xp does not seem to.

You can still try the "Build" menu -> "Run Code Analysis on Solution" (or hit the hotkey Alt-F11) but this will, if this is your problem, give you "error MSB8026: Static analysis is not supported with the current platform toolset."

If that doesn't work, try project properties -> C/C++ -> General -> SDL checks and setting that to "Yes (/sdl)". I vaguely remember that it didn't show up for me until I did that, but even when I remove that option again, the code analysis option doesn't go away, so might not be related.

If you need (as I do) a different platform toolset for your normal builds, which does not support code analysis, then rather than beak your Debug or Release configurations, it may be better to create a separate "Analyze" configuration: project properties -> "Configuration Manager" -> Active solution configuration -> "New..." -> type "Analyze", copy across the settings from "Debug". Then you can set the platform toolset in there, and enable analysis, and not worry about it breaking your normal configurations.

Even after all that though, I can't get it to find any errors, even though I know errors exist. So, ymmv.



回答2:

Code Analysis does indeed exist in Visual Studio 2012 Express Edition. It has been present since the initial release and is still present after Update 3.

To run code analysis on a project or solution:

  1. Open the project or solution
  2. From the Solution Explorer right click on the project or solution you want to run Code Analysis on
  3. From the right click menu choose Run Code Analysis.

Having completed the steps above you should see the Code Analysis user interface which should look similar to:

Settings to control Code Analysis are found in project properties on the Code Analysis tab. Specifically in Visual Studio Express for Desktop, I am able to control:

  • Whether or not Code Analysis runs on build
  • Suppression of Code Analysis results for managed code that has been generated.

For reference, I tested this in Visual Studio Express Edition 2012 for Desktop with Update 3 applied. I can confirm the option is present for C# and Visual Basic projects



回答3:

I'm using Visual Studio 2013, but my solution was to change the Target Platform in the Project settings.

Project Properties -> Configuration Properties -> General -> Platform Toolset -> VS2013 (v120), instead of VS2013 - Windows XP)