In Visual Studio, I can select the "Treat warnings as errors" option to prevent my code from compiling if there are any warnings. Our team uses this option, but there are two warnings we would like to keep as warnings.
There is an option to suppress warnings, but we DO want them to show up as warnings, so that won't work.
It appears that the only way to get the behavior we want is to enter a list of every C# warning number into the "Specific warnings" text box, except for the two we want treated as warnings.
I am checking a file in to source control to keep track of which ones we are treating as errors
C# 3.5 warning numbers to treat as errors:
183,184,197,420,465,602,626,657,658,672,684,688,809,824,1058,1060,1200,
1201,1202,1203,1522,1570,1574,1580,1581,1584,1589,1590,1592,1598,1607,
1616,1633,1634,1635,1645,1658,1682,1683,1684,1685,1687,1690,1691,1692,
1694,1695,1696,1697,1699,1707,1709,1720,1723,1911,1956,1957,2002,2014,
2023,2029,3000,3001,3002,3003,3004,3005,3006,3007,3008,3009,3010,3011,
3012,3013,3014,3015,3016,3017,3018,3022,3023,3026,3027,5000,108,114,162,
164,251,252,253,278,279,280,435,436,437,440,444,458,464,467,469,472,618,
652,728,1571,1572,1587,1668,1698,1710,1711,1927,3019,3021,67,105,168,169,
219,282,414,419,642,659,660,661,665,675,693,1700,1717,1718,28,78,109,402,
422,429,628,649,1573,1591,1610,1712,3024
C# 3.5 warning numbers that remain as warnings:
612 - X is obsolete
1030 - #warning This is a warning
1701, 1702 - Warnings that are suppressed by the C# compiler by
default and shouldn't show up at all.
The biggest disadvantage to this approach is that a few warnings do not have numbers, so they can't be referenced explicitly. For example, "Could not resolve this reference. Could not locate assembly 'Data....'"
Does anyone know of a better way to do this?
Clarifying for those who don't see immediately why this is useful. Think about how most warnings work. They tell you something is a little off in the code you just wrote. It takes about 10 seconds to fix them, and that keeps the code base cleaner.
The "Obsolete" warning is very different from this. Sometimes fixing it means just consuming a new method signature. But if an entire class is obsolete, and you have usage of it scattered through hundreds of thousands of lines of code, it could take weeks or more to fix. You don't want the build to be broken for that long, but you definitely DO want to see a warning about it. This isn't just a hypothetical case--this has happened to us.
Literal "#warning" warnings are also unique. I often want to check it in, but I don't want to break the build.