问题
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
'Missing XML comment for publicly visible type or member...'
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>
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?
I can't just add a pragma disable
into the auto generated code or disable Xml
comments.
回答1:
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.
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...
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.
回答2:
I also found that I can set the Service Reference
as Internal
on creation, which gets around the Xml
summary problem.
Although this still leaves me with the problem of suppressing StyleCop
errors for the generated code, but I will create a new question for this.
来源:https://stackoverflow.com/questions/14852103/suppress-xml-warning-for-servicereference-cs-file