Terje Sandstrom

------ Chief Software Geek at Inmeta Consulting in Scandinavia ----- and a Visual Studio ALM MVP

  Home  |   Contact  |   Syndication    |   Login
  59 Posts | 1 Stories | 95 Comments | 0 Trackbacks

News

Subscribe

Delicious Save this on Delicious Visual Studio Feeds

¨

Tag Cloud


Article Categories

Archives

Post Categories

Image Galleries

Company stuff

Interesting bloggers

Interesting companies

Microsoft

Microsoft Norge

Microsoft Regional Directors

Microsoft Test

MSFT Blogs

MVP

NNUG

Other interesting stuff

TFS

Visual Studio

Background

You are opening a solution made in Visual Studio 2010 with VS 2012.  When you run Code Analysis you get a series of CA0053 errors, saying it is unable to load the rule sets from the Visual Studio 2010 directory!

In the Error window you get an error message saying “Code Analysis detected errors.”

image

And in the Code Analysis window you will get the “CA0053 Error running code analysis” with its “Unable to load rule assembly”.

clip_image001

This means the project is bound to Visual Studio 2010, where it should have been Visual Studio version independent. The absolute path to the Visual Studio 10 binaries is what causes the problem.

What has happened was that this certain VS2010 specific information was “inadvertently” introduced in SP1, and it has not been fixed in any later update.

It does NOT happen if you run in Debug|x86 or Release|x86, but any other configuration you have added will give you this error.

Fixing the error

The error must be fixed by changing the project files.  If you have only a few projects in your solution, you can fix them manually.  If you have a lot of projects in your solution, I have uploaded a small tool to help in the process.  After the fix, the projects will work both in VS 2010 and in VS 2012 with no side effects.

The error seems to be introduced only when a new configuration is created.  Subsequent changes to an existing configuration doesn’t seem to reintroduce the error.  So the fixes below will stay fixed.  Be aware that if anyone adds a new configuration using VS 2010, the error will be introduced again for that new configuration.  Then run the fix again.

Update:  It has been reported that also other changes you do (not identified which yet) may revert the change, see for example this blogpost.

The bug is fixed in VS2012 however, so if you use VS 2012 to add new configuration, all will be well, and those configurations will be backward compatible with VS 2010.

Manual fix

Open the project file in an editor.

You do this by right click the project in the solution editor and either choose “Edit Project File” or “Unload Project” followed by “Edit” afterwards.

Now find all occurrences of the string “Microsoft Visual Studio 10.0

They should all be in two fields, named <CodeAnalysisRuleDirectories> and <CodeAnalysisRuleSetDirectories>. 

Alternative 1:  The very safe way

Replace the content to be as follows:

<CodeAnalysisRuleDirectories>$(DevEnvDir)\..\..\Team Tools\Static Analysis Tools\FxCop\Rules</CodeAnalysisRuleDirectories>

<CodeAnalysisRuleSetDirectories>$(DevEnvDir)\..\..\Team Tools\Static Analysis Tools\Rule Sets</CodeAnalysisRuleSetDirectories>

Alternative 2: Which seems to work

Simply delete the fields completely. 

It seems to work in the conditions I have tested, but if you should get into a condition where it doesn’t work, go back to alternative 1 for that case.  And please, send me a note, I would like to know.

(I noted this blogpost by Alun Jones , where he deleted only the content of the field, that should also work)

PS:  Why not use Find/Replace:  You can try, but the full content of the fields will differ dependent upon what operating system you run, x86 or x64, and if both have been used, for example because your team’s developers have both, all of these paths will be written into these fields.  That is at least 4 permutations.  A tool is better!

 

Automatic fix using the FixCA0053 tool

The tool can be downloaded from Visual Studio Gallery here.   Place it somewhere easy to find.

Open a command line window, and go down to the top directory of your project. 

Then simply call the program from there.

The program will locate all the csproj files from that location and in all subdirectories of that location, and change the fields as in Alternative 1 above.

The tool will output how many files it fixed, and how many was skipped because the error was not there. 

image

TIP

If it tells you it could not write to some files, you have probably forgot to check them out.  To check out ONLY the csproj files (In Solution Explorer it will check out all files, you may not want that), use the Source Control Explorer, go to the location where you want to start, right click and choose Find in Source control/Wildcard.  Enter the Wildcard “*.csproj” and check Recursive.  In the next window coming up, you can select all the files, right click and choose “Check out”.

Source code

The source code can be found at https://github.com/OsirisTerje/FixCA0053 

posted on Saturday, August 18, 2012 9:24 PM

Feedback

# re: How to fix the CA0053 error in Code Analysis in Visual Studio 2012 10/3/2012 1:33 AM Matt
Thank you sir, it worked a charm

# re: How to fix the CA0053 error in Code Analysis in Visual Studio 2012 11/9/2012 9:17 PM Roman
Great! Thanks a lot! That fixed my problem!

# re: How to fix the CA0053 error in Code Analysis in Visual Studio 2012 11/29/2012 4:33 PM Demian
Hi
I should also remove the absolute paths in our custom rulesets:
<RuleHintPaths>
<Path>C:\Program Files (x86)\Microsoft Fxcop 10.0\Rules</Path>
</RuleHintPaths>


# re: How to fix the CA0053 error in Code Analysis in Visual Studio 2012 1/28/2013 7:42 PM geoffsh
Excellent! Wish I had found it before spending hours trying to solve this. If we were co-workers, I would take you to lunch.

# re: How to fix the CA0053 error in Code Analysis in Visual Studio 2012 1/28/2013 10:22 PM Terje
Thanks !! Nice to hear it helps :-)

# re: How to fix the CA0053 error in Code Analysis in Visual Studio 2012 2/20/2013 1:04 PM Olcay Seker
Nice tip. but it worked for me after i deleted every node which contains codeanalysis.

# re: How to fix the CA0053 error in Code Analysis in Visual Studio 2012 3/2/2013 1:09 AM Richard
Yep just downloaded and used the tool. Works great thanks.

# re: How to fix the CA0053 error in Code Analysis in Visual Studio 2012 8/15/2013 1:07 PM Ralph Jansen
I like your post. It solved my problem. It only took me another 14 hours to figure out that one of my solution files didn't migrated to VS2012. I still had this same error. The fix for this was opening the solution file in Notepad and edit the format version to 12 (it was 11) and on the next line change the visual studio instance to Visual Studio 2012 (it was Visual Studio 2010). See my post for the solution.
http://www.locktar.nl/general/how-to-fix-the-ca0053-error-in-code-analysis-in-visual-studio-2012/

# re: How to fix the CA0053 error in Code Analysis in Visual Studio 2012 8/15/2013 10:31 PM Terje
Thanks! Great catch ! (Reading your post) The upgrade wizard should see that the 2nd solution also needed an upgrade, this sounds like a bug in VS to me.

# re: How to fix the CA0053 error in Code Analysis in Visual Studio 2012 10/9/2013 1:10 PM Srividya
Hi
I am getting the below error, As stated in the blog i was unable to find out any CodeAnalysisdirectory in the project file. Any help would be appriciated


CA0053 Error Running Code Analysis CA0053 : Unable to load rule assembly 'c:\program files (x86)\microsoft visual studio 11.0\team tools\static analysis tools\fxcop\rules\microsoft.visualstudio.codeanalysis.dll': The assembly contains no FxCop rules. [Errors and Warnings] (Global)


# re: How to fix the CA0053 error in Code Analysis in Visual Studio 2012 10/9/2013 1:37 PM Terje
Do I understand you correctly that this happens for a non-migrated program ? You have started out in VS 2012 ?
Which version and edition are you running ?
Is this related to just this project/solution or any solution/project you add ?
If you open the project file, you should at least see something like:
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
A standard VS 2012 project file doesnt have the fields mentioned in the post above, and don't need them either, so when you get the CA0053 in this case, there seems to be something with your installation.

# re: How to fix the CA0053 error in Code Analysis in Visual Studio 2012 10/17/2013 5:47 PM Karl Shifflett
Still broken in VS 2013 RTM. :-(

# re: How to fix the CA0053 error in Code Analysis in Visual Studio 2012 11/6/2013 1:17 PM Ralph Jansen
See my updated blog post for VS2013 on http://www.locktar.nl/general/how-to-fix-the-ca0053-error-in-code-analysis-in-visual-studio-2012/

# re: How to fix the CA0053 error in Code Analysis in Visual Studio 2012 1/23/2014 10:41 PM Jeffry van de Vuurst
1,5 years after your post and still helpful. Thanks!

# re: How to fix the CA0053 error in Code Analysis in Visual Studio 2012 1/23/2014 10:43 PM Terje
Great to hear !

Terje :-)

# re: How to fix the CA0053 error in Code Analysis in Visual Studio 2012 1/29/2014 12:18 PM Christ Hagenaars
Great, worked for me!

# re: How to fix the CA0053 error in Code Analysis in Visual Studio 2012 3/6/2014 10:52 PM DK
To get "Find in Source Control" feature you need to install Team Foundation Server Power Tools.

# re: How to fix the CA0053 error in Code Analysis in Visual Studio 2012 3/7/2014 12:11 AM Terje
Thanks for pointing that out, sometimes hard to say what extension is in or not. I got a list here of what I do have installed and recommends. http://geekswithblogs.net/terje/archive/2013/12/14/visual-studio-amp-tfs-2013-ndash-list-of-extensions-and.aspx

Post A Comment
Title:
Name:
Email:
Comment:
Verification: