将警告视为错误无效 [英] Treat Warnings as Errors has no effect

查看:98
本文介绍了将警告视为错误无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio中项目的设置中,我已将警告作为错误警告设置为全部。
警告级别设置为4。
我通过有意引入违反CA1305的代码进行了测试,但是它成功构建(并重建),并返回警告。
我期望的是构建将失败并且将返回错误。我的理解是错误的吗?

In my project's settings in Visual Studio, I have set 'Treat warnings as errors' to 'All'. The Warning level is set to 4. I tested this by deliberately introducing code that violates CA1305, but it builds (and rebuilds) successfully, returning a Warning. What I expected was that the build would fail and an Error would be returned. Is my understanding wrong?

推荐答案

代码分析使用另一种机制将警告视为错误。要对代码分析警告进行处理,请向您的解决方案中添加一个新的代码分析规则集。为此,请右键单击您的解决方案,然后选择添加新项目...。搜索规则集,然后选择添加新的代码分析规则集。给它提供您想要的任何名称。

Code Analysis uses a different mechanism to treat warnings as errors. To have Code Analysis warnings treated as such, add a new Code Analysis Ruleset to your solution. To do so, rightclick your solution and choose "Add new item...". Search for "Rule Set" and select to add a new "Code Analysis Rule Set". Give it any name you want.

在规则集编辑器中,选择要包含在项目中的规则,并将其设置为错误。您可以选择将哪些规则视为错误,将哪些规则视为警告。

In the Rule Set Editor, select the rules you want to include in your project and set them to Error. You can choose which rules to treat as errors and which as warnings.

在代码分析规则集属性窗口中设置规则集的名称,然后保存它。然后打开分析->配置解决方案的代码分析 菜单项。

Set the name for the rule set in the Code Analysis Ruleset properties window and save it. Then open the Analyze->Configure Code Analysis for Solution menu item.

为您的项目选择错误规则集并应用。

Select your "As Error" ruleset for your projects and apply.

这篇关于将警告视为错误无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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