Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warnings as Errors versus Deprecated Attribute in Visual Studio

We like the Warnings as Errors setting as we have a policy of not checking in code with warnings and this is the only effective way we have found to enforce it.

We also like to use the Obsolete attribute to flag methods that should not be used any more.

Problem is that adding a Obsolete attribute to a method or class immediately causes tons of projects to not build (not to mention problems if a .NET API call is deprecated).

Does anyone have a good solution to this?

We want a visible, hard-to-ignore indicator that you are using a deprecated API but that does not cause the build to fail. We want to see the warnings in the IDE and in CI builds.

like image 628
Kevin Lawrence Avatar asked Jan 04 '11 23:01

Kevin Lawrence


People also ask

How do I show warnings in Visual Studio?

To display the Error List, choose View > Error List, or press Ctrl+\+E.

How do I enable compiler warnings in Visual Studio?

If you want to turn it on (or off) in the project setting, you have to go to: Configuration Properties -> C/C++ -> Command Line and then under Additional Options you can enter: /w3#### to set your warning to level 3, and thus enable it; or you can enter /wd#### to disable a warning.


1 Answers

This other stack overflow post should help: https://stackoverflow.com/a/468166/9195608

Basically it says:

You can add a WarningsNotAsErrors-tag in the project file.

<PropertyGroup>
    ...
    ...
    <WarningsNotAsErrors>612,618</WarningsNotAsErrors>
</PropertyGroup>

Note: 612 and 618 are both warnings about Obsolete

The difference between 612 and 618 is the comment of the ObsoleteAttribute. An ObsoleteAttribute without comment generates the error 612, and one with a comment generates 618.

like image 93
Christopher Wood Avatar answered Sep 24 '22 13:09

Christopher Wood