禁止 ServiceReference .cs 文件的 Xml 警告 [英] Suppress Xml warning for ServiceReference .cs file

查看:29
本文介绍了禁止 ServiceReference .cs 文件的 Xml 警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 MVC4VS2012,我正在使用 Service Reference,它会自动生成一个 Reference.cs> 文件.当我构建时,我收到数十个警告作为错误,阅读

Working with MVC4 and VS2012, I am using a Service Reference, which auto generates a Reference.cs file. When I build, I get dozens of warnings as errors that read

'缺少公开可见的类型或成员的 XML 注释...'

'Missing XML comment for publicly visible type or member...'

我在 here 中找到了类似的答案,它引用了一个在此博客,建议将以下修复添加到 CSProj 文件中:

I have found a similar answer here, which references a workaround found in this blog, which suggests adding the following fix into the CSProj file:

<Target Name="XamlGeneratedCodeWarningRemoved" AfterTargets="XamlMarkupCompilePass1">
    <Exec Command="for %%f in (@(XamlGeneratedCodeFiles)) do echo #pragma warning disable > %%f.temp" />
    <Exec Command="for %%f in (@(XamlGeneratedCodeFiles)) do type %%f >> %%f.temp" />
    <Exec Command="for %%f in (@(XamlGeneratedCodeFiles)) do copy /y %%f.temp %%f" />
    <Message Text="XamlGeneratedCodeWarningRemoved: @(XamlGeneratedCodeFiles)" />
  </Target>

但这似乎不适用于 Reference.cs 文件,可能是因为它针对的是 Xaml?谁能告诉我如何解决这个问题以使用 Reference.cs 文件或建议另一种方法来解决这个问题?

But this doesn't seem to work with the Reference.cs file, probably because it is targeting Xaml? Could anyone tell me how I can fix this to work with Reference.cs file or suggest another way to get around this problem?

我不能只是在自动生成的代码中添加 pragma disable 或禁用 Xml 注释.

I can't just add a pragma disable into the auto generated code or disable Xml comments.

推荐答案

动态更新预先生成的 .cs 文件将 导致 Visual Studio 出现各种问题,因为它将使用文件的内存副本.而且由于源代码管理集成使文件成为只读并且需要在每次构建后检入文件,这将非常令人恼火.

Updating the pre-generated .cs files on the fly will cause all sorts of issues with Visual Studio, since it will use the in-memory copy of the files. And it will be very irritating due to the Source Control integration making the files read-only and requiring the files to be checked in after every build.

您还可以通过调整其属性来使您的服务客户端成为内部.根据您的设置,文档生成不会抱怨任何外部不可见的方法.不过,这可能仍会触发 StyleCop、代码分析或 Resharper 警告...

You can also make your Service Client internal by tweaking it's properties. Depending on your settings, the documentation generation will not complain about any method that isn't externally visible. This might still trigger StyleCop, Code Analysis or Resharper warnings though...

所以我通常做的是,我将服务引用粘贴到他们自己的 Visual Studio 项目中,将生成的代码设为公开并关闭整个项目的文档生成.这还有一个好处,即无论您将其包含在哪个项目中,您的服务引用都将使用相同的绑定.

So what I usually do is, I stick the Service References in their own Visual Studio project, make the generated code Public and turn off documentation generation for the whole project. This also has the advantage that your service reference will use the same bindings regardless of the project you include it in.

这篇关于禁止 ServiceReference .cs 文件的 Xml 警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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