Categories
geek programming tips

how to use code analysis in visual studio and not go crazy

An artistic screenshot of Visual Studio.

Code Analysis in Visual Studio is great to have your .NET code checked automatically against the .NET framework design guidelines, coding standards and good practices. By activating CA, you’ll pick up some of these practices along the way and as a result you’ll be writing better code, aided by this automated tool.

The downside is that sometimes CA can make you go stark raving mad when you are in the process of sketching or refactoring some code. When you want to quickly draft some code or try something out to see if that hack you have in mind would work, CA gets in the way as it keeps bitching about naming conventions, literal string values and what not.

So how do you make CA shut the F* up in a case like that?
Well it’s quite simple, you just have to add this line as the first in your cs file:

// <auto-generated />

You have now fooled CA into thinking the file is auto-generated by some tool and it will effectively STFU.
Awesome.

Don’t forget to remove that line again afterwards of course.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.