Tuesday, September 8, 2009

Tired of "Obsolete" warnings on your project?

If you are like me, find yourself marking old code bits as "Obsolete" but have to keep them in your project for backward compatibility - you must be tired of all the visual studio warnings regarding using obsolete code - especially if it is your own code.

In most cases I have an "Upgrade" method that identifies old version installations and upgrade them to newer version constructs, but in this upgrade code I have to use some of the old obsolete code generating these annoying warning.

BUT - I do not wish to disable all Obsolete warnings - some are very important and I do wish VS to keep warning me about them.

So, the proper way to go is to mark specific code bits not to throw any warnings about using obsolete code. Like: telling the VS that within a specific code block I am aware that I am using some obsolete code and I don't want it to show in my build results.

I came accross the simple solution here that saved me a lot of time figuring out the correct pragma statement for this:
http://stackoverflow.com/questions/344630/ignore-obsoleteattribute-compiler-error

Here, Nick Bolton simple says:
"
What about using #pragma to disable the warning around the specfic code?
#pragma warning disable 0612
// Call obsolete type/enum member here
#pragma warning restore 0612
"


And guess what? It did the trick for me!

No comments: