我们喜欢警告作为错误设置,因为我们有一项政策,即不签入带有警告的代码,这是我们发现执行该政策的唯一有效方法。
我们还喜欢使用过时属性来标记不应再使用的方法。
问题是,向方法或类添加 Obsolete 属性会立即导致大量项目无法构建(更不用说不推荐使用 .NET API 调用时出现的问题)。
有人对此有好的解决方案吗?
我们需要一个可见的、难以忽略的指示器,表明您正在使用已弃用的 API,但不会导致构建失败。我们希望在 IDE 和 CI 构建中看到警告。
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.
发布评论
评论(3)
一个简单的解决方案是使用构建配置(例如调试构建配置),而不将警告视为错误。然而,如果重点是向您的开发人员标记构建过程中出现问题,那就不好了,因为他们会忘记在签入之前进行发布构建。
或者,您可以设置“警告作为错误”,而不是使用“警告作为错误”建立你的规则集来引发错误本身而不是发出警告。当然,这意味着非 CA 警告不会导致错误。
我认为最好的解决方案是在服务器端处理它。理想情况下,您应该有某种门控签入,以便您的代码存储库拒绝未使用其构建定义进行构建的提交(打开警告作为错误,并且您的开发人员可以关闭警告作为错误)。我怀疑这是 TFS-2k10 独有的功能。
A simple solution would be to have a build configuration (e.g. your debug build configuration) without warnings as errors. If, however, the point is to flag to your developers that something is wrong on build, that's no good as they'll forget to do a release build before they check in.
Alternately, rather than using "warnings as errors" you could set up your ruleset to throw errors itself rather than raise warnings. This will mean, of course, that non-CA warnings won't cause errors.
The best solution, I think, would be to handle it on the server side. Ideally you'd have some sort of gated checkin so that your code repository rejects commits that don't build using its build definition (with warnings-as-errors on, and your developers can leave warnings-as-errors off). I suspect that's a TFS-2k10-only feature though.
其他堆栈溢出帖子应该有所帮助:
https://stackoverflow.com/a/468166/9195608
基本上它说:
This other stack overflow post should help:
https://stackoverflow.com/a/468166/9195608
Basically it says:
如此处所述 /sdl(启用附加安全检查),如果关闭 SDL,编译器会将其视为警告。
As explained here /sdl (Enable Additional Security Checks), if you switch off SDL the compiler will treat it as a warning.