Issues with mixed C++ and C# projects in Visual Studio 2012 running Code Analysis

Issues with mixed C++ and C# projects in Visual Studio 2012 running Code Analysis

If you have projects created under Visual Studio 2010 (SP1), and mixed C++ and C# projects in the solution, and you are using other configurations than Debug/Release x86 you may hit a very strange situation when you run the Static Code Analysis, either alone, or as part of the build.

You may get into a situation which seems like things go in circles.  One error points to a place where it simply points back to the first one.  This is in fact, two kind of errors causing this behavior.

Now, what you see is this:

image

The new Code Analysis window tells you it has issues around the platform toolset,  pointing you to the Error list, which just tells you that Code Analysis has detected errors, and points you back to the Code Analysis Window, or ask you to look up the log, which whereabouts is not known…….

This situation is caused by two different errors working in (dis)harmony.

The first issue is the platform issue.  The Code Analysis window will only show warnings/errors from a C++ project if the platform toolset is set to VS 2012.  If you have created this solution/project in VS 2010, it will be set to VS 2010.  All errors from the VS 2010 C++ code analysis will then be shown in the Error list window, and not in the new Code Analysis window.

If you look in the project properties for a C++ project you find this setting under Configuration Properties/General – Platform Toolset, and the possible values are either Visual Studio 2010 (v100) or Visual Studio 2012 (v110) (or VS2008 which is v90). 

image

If this is set to anything but v110, the list of Code Analysis errors will go to the Error Window.

Now, this is fine, except, it doesn’t get there….

Which is caused by another error which is not shown now, it would have been shown in the Code Analysis window, if it hadn't been covered by this error.  This is the CA00053 error, an error in the csproj project file caused by a VS 2010 SP1 error.  It has been fixed in VS 2012, but is still in VS 2010, so any project you move over from VS2010 is suspect to have this issue.  See this blog post for more information on how to handle this error, there is even a tool to fix the project file.   https://geekswithblogs.net/terje/archive/2012/08/18/how-to-fix-the-ca0053-error-in-code-analysis-in.aspx 

So, fix your project files, using the tool at http://visualstudiogallery.msdn.microsoft.com/471da13b-d415-4a44-a4e9-a8222316b902, then you will see the analysis errors/warnings  in the error windows, your build will not be broken, and in the Code Analysis window you will just get the warning above.

This article is part of the GWB Archives. Original Author: terje

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.