如何禁用“警告错误”仅适用于生成的文件? (MSBuild)
在我们的持续集成服务器 (Teamcity 5.1.3) 上,我们有一个 msbuild 脚本,可以自动构建我们的应用程序。
当我们在 Visual Studio 中启用“警告为错误”时,它会正常构建(它会忽略“*.designer.cs”文件中的方法。但在构建服务器上,我们总是收到以下错误:
[(Rebuild target(s)):] somefile.Designer.cs(XX, XX): error CS1591: Warning as Error: Missing XML comment for publicly visible type or member...
正在使用的 MSBuild 脚本看起来像这样:
<MSBuild Projects="proj\$(ProjectName).sln"
Targets="Clean;Rebuild"
Properties="Configuration=Release"
StopOnFirstFailure="True">
</MSBuild>
我可以理解为什么这样做,但是必须有一种方法告诉 msbuild 忽略生成文件中缺少的注释?
EDITED
进一步挖掘: 在 Visual Studio 解决方案中,我们选中了“警告错误”,但我们还添加了“抑制警告”文本框中列出的错误 1591。 MSBuild 似乎没有选择“抑制警告”文本框并导致构建失败。有什么我可以做的吗?
再次编辑 问题是 MSBuild 的目标是任何 CPU(并且在“ANY CPU”配置中我们没有抑制错误 1591)。一旦我们更改了任何 CPU 以排除错误 1591,一切就开始在构建服务器上正确构建。感谢那些提供帮助的人。
On our continous integration server (Teamcity 5.1.3) we have a msbuild script that is automatically building our applications.
When we enable "Warning as error": in Visual Studio, it build fine (it ignores the methods within "*.designer.cs" files. But on the build server we always receive the following error:
[(Rebuild target(s)):] somefile.Designer.cs(XX, XX): error CS1591: Warning as Error: Missing XML comment for publicly visible type or member...
The MSBuild script that is being used looks like this:
<MSBuild Projects="proj\$(ProjectName).sln"
Targets="Clean;Rebuild"
Properties="Configuration=Release"
StopOnFirstFailure="True">
</MSBuild>
I can understand why it does that, but there must be a way to tell msbuild to ignore missing comments in generated files?
EDITED
Digging a little further:
In the Visual Studio Solution we had "Warning as error" checked but we also add error 1591 listed in the "Suppress warning" textbox. MSBuild does'nt seem to pick up that "suppress warning" textbox and fails the build. Anything I can do?
EDITED Again
The problem was that MSBuild was targetting any CPU (and in the "ANY CPU" configuration we didnt suppressed error 1591). Once we changed ANY CPU to exclude error 1591 it all started to build correctly on the build server. Thanks for those that helped.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过在 msbuildcall 中添加以下属性来忽略注释警告:nowarn="1591,1573"。
You can ignore comments warning by adding the following property in your msbuildcall : nowarn="1591,1573".
不,MSBuild 对 XML 注释并不挑剔。无论您使用什么代码分析工具。猜测类似 StyleCop 的东西。它确实抱怨这个确切的问题,它不是很聪明,与 Windows 窗体项目模板差不多。
只有当您在开发人员上实施与应用于构建服务器相同的构建规则时,您才能解决这个问题。因为需要其中之一来编辑 Mumble.Designer.cs 文件中的请勿编辑代码并应用 [GenerateCode] 属性。现在不在那里了。
这是一个政治问题,我无法真正帮助你解决这个问题。在不同时间和不同建筑物中从事此工作的微软团队也同样如此。但如果你要求开发人员解决问题,你可以指望他们大声叫喊。
使其保持一致。
No, MSBuild isn't picky about XML comments. Whatever code analysis tool you use is. Guessing at something like StyleCop. It does complain about this exact problem, it's not very smart, about on par with the Windows Forms project templates.
You are only ever going to solve this problem if you enforce the same kind of build rules on the devs as you apply to the build server. Because it will take one of them to edit the do-not-edit code that it is in a Mumble.Designer.cs file and apply the [GeneratedCode] attribute. It is not there now.
That's a political problem, one I cannot really help you with. Nor the Microsoft groups that worked on this at different times and different buildings. But you can count on the devs barking loudly if you ask them to solve the problem.
Make it consistent.
对我来说,问题仅发生在具有 SOAP 服务引用的 dll 项目上。当我在“构建”选项卡上打开项目设置时,我注意到选中了一个名为“XML 文档文件”的复选框。这就是强制 SOAP 服务的每个公开成员发表评论的原因!
For me the problem was happening only on a dll project with a SOAP service reference. When I opened the project settings on Built tab I noticed a checkbox called "XML Documentation file" is checked. That was the reason behind forcing every exposed member of the SOAP service to have a comment!