Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress Xml warning for ServiceReference .cs file

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.

like image 788
DevDave Avatar asked Feb 13 '13 11:02

DevDave


People also ask

How do I ignore warnings in C#?

Use a #pragma warning (C#) or Disable (Visual Basic) directive to suppress the warning for only a specific line of code.

How do I ignore a warning in Visual Studio?

Turn off the warning for a project in Visual StudioSelect the Configuration Properties > C/C++ > Advanced property page. Edit the Disable Specific Warnings property to add 4996 . Choose OK to apply your changes.

What is the advantage of using XML comments?

XML comments help speed development by providing IntelliSense on custom methods and other code constructs. XML comments encourage code reuse by providing a path to generate API style reference documentation from your source code.


2 Answers

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.

like image 122
jessehouwing Avatar answered Sep 24 '22 15:09

jessehouwing


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.

like image 23
DevDave Avatar answered Sep 21 '22 15:09

DevDave