Domanda

We use code analysis on our projects, and also enabled the 'XML documentation file:' option in our project settings. Also we have set 'Treat warnings as errors' to All.

On the code analysis tab, we checked the option 'Suppress results from generated code (managed only).

Now we use the 'Activity' item in C#, that will create a xaml file. When building the xaml files will create *.g.cs files. And now the code analysis keeps complaining about these auto-generated classes. Also the build will fail because of the missing xml documentation in the *.g.cs files.

We cannot find a way to suppress these things, i think VS should skip these auto-generated files, but is does not.

Is there a way to actually skip these files? We want all other code in the project to comply with our standards code analysis and xml documentation.

If we could somehow edit the templates (generation code) that generate the *.g.cs files, we might be able to get around this Visual Studio problem. But where are those t4-templates (or are those files not t4 templates?)

È stato utile?

Soluzione

This has nothing to do with Code Analysis, which is why its generated code setting isn't relevant. The C# compiler is generating the warning (which you are treating as an error) for the lack of xmldoc comment on the class and constructor.

Unfortunately, the approach used for generating the .g.cs file is hardcoded in Microsoft.Build.Tasks.Xaml.ClassGenerator (in XamlBuildTask.dll). It does not use a template, and there's no way to override just part of its behavior.

I can see only two relatively simple approaches that don't involve replacing the entire class generation mechanism:

  1. Generate your activity class with internal instead of public visibility if that works for your scenario (see http://msdn.microsoft.com/en-us/library/ms754029(v=vs.110).aspx for details).
  2. Move just your activities to a separate project that disables the CS1591 compiler warning.

Either way, you might want to submit a request at http://visualstudio.uservoice.com/ for the .g.cs file generation to be moved to a templated approach.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top