"所有警告视为错误,除非..."在Visual Studio中 [英] "Treat all warnings as errors except..." in Visual Studio

查看:882
本文介绍了"所有警告视为错误,除非..."在Visual Studio中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio中,我可以选择将警告视为错误选项,以prevent从是否有任何警告编译我的code。我们的团队使用此选项,但有两个警告我们要继续的警告。

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.

有是燮preSS警告选项,但我们希望他们显示为警告,因此,这是行不通的。

There is an option to suppress warnings, but we DO want them to show up as warnings, so that won't work.

看来,要得到我们想要的行为的唯一方法是进入每一个C#警告编号列表进入特别警告文本框中,除了我们要当作警告两人。

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警告号码当作错误:

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警告编号:

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?


澄清那些谁不立即看到为什么这是有用的。想想看,大多数的警告是如何工作的。他们告诉你的东西是有点过了code你刚才写的。大约需要10秒钟解决这些问题,并保持code基清洗剂。

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.

在过时的警告是从这个非常不同。有时修复它只是意味着消费的新方法签名。但是,如果整个类是过时的,你拥有它的使用分散到$ C $行C几十万,这可能需要数周或更长时间修复。你不想长期被该打破的身材,但你肯定希望看到一个关于它的警告。这不只是一个假设的情况 - 这发生在我们身上。

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.

文字指令#warning的警告也很独特。我经常希望的检查它,但是我不想打破建设。

Literal "#warning" warnings are also unique. I often want to check it in, but I don't want to break the build.

推荐答案

您可以添加 WarningsNotAsErrors -tag在项目文件。

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

<PropertyGroup>
    ...
    ...
    <WarningsNotAsErrors>618,1030,1701,1702</WarningsNotAsErrors>
</PropertyGroup>

请注意: 612 618 即将过时的,不知道其中的差别,但这个项目我都警告M工作报告是用过时警告618。

Note: 612 and 618 are both warnings about Obsolete, don't know the difference but the project i'm working on is reporting Obsolete with warning 618.

这篇关于&QUOT;所有警告视为错误,除非...&QUOT;在Visual Studio中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆