How to fix the CA0053 error in Code Analysis in Visual Studio 2012

I upgraded one big Team project with a lot of different solutions (to separate stuff) to Visual Studio 2012. The custom Code Analysis gave me an CA0053 error on the build server. So I searched for the problem and came to this great blog post: How to fix the CA0053 error in Code Analysis in Visual Studio 2012. This solved my problem. I removed all the tags CodeAnalysisRuleDirectories and CodeAnalysisRuleSetDirectories. This was enough. Now Visual Studio 2012 would get the latest Code Analysis dll’s.

When queued another build, I still got the same error. This was not in all solutions so it had something to do with the solution file or with some of the projects inside it. After removing the project one at the time (after each try the build succeeded) I did a reset of the solution file so that was the same. At the end, all projects where the same and I still got the error. I then searched for a difference between solutions files.

There was the solution, the version of the file format was different and the Visual Studio version was different.

image

I think that I know what the cause of the problem is. Because we have a lot of different solution files (with overlapping projects in it), all the upgrades to Visual Studio 2012 where already done. Because they where already done, no file change was done so the format file version wasn’t migrated to the Visual Studio 2012 version. The custom ruleset in the projects where searching for the Visual Studio 2012 dll’s but the solution was build in Visual Studio 2010 on the build server because of the different format version.

Hopefully this fix will help someone. Let me know!

 

Update 11/06/2013:

We upgraded our solution to VS2013 and the Custom Code Analysis didn’t work again. So I builded the custom rules in VS2013 and used that version of the DLL. Now the clients worked again. When I started a CI build, the build failed with the CA0053 error. It seems that the build server has (in my opinion) a bug that it uses the format version of your solution file -1 to determine the Visual Studio version. Visual Studio 2013 uses the same format version as VS2012 (version 12) so you will end up with VS2012 on the build server. But because we have builded the custom rules against VS2013, the buildserver wont recognize the rules. The solution is to add the /p:VisualStudioVersion=12.0 parameter by the “MSBuild Argurments” in your CI build definition.

Leave a Reply