I'm using a .Settings file in my Visual Studio 2008 project which auto-generates a Settings.Designer.cs file from the PublicSettingsSingleFileGenerator custom tool.
This works fine, but I also want to enable "Warnings as Error" in the compilation options, to force everyone to keep the XML comments up to date, but I don't know how to add comments to all of the elements within the auto-generated code.
The actual properties can have comments added by selecting the elements in the design view and adding a "Description" within the properties window. But there doesn't seem to be a way to do this for the class declaration, or the default instance property.
Steps to reproduce this problem are as follows
and this is the code which is generated in the PublicSettingsSingleFileGenerator Settings.Designer.cs file
namespace SettingsTest {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")]
public sealed partial class Settings1 : global::System.Configuration.ApplicationSettingsBase {
private static Settings1 defaultInstance = ((Settings1)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings1())));
public static Settings1 Default {
get {
return defaultInstance;
}
}
}
}
Not sure if this extra info should be part of the question section, as it goes some way to pointing at an answer
According to this link the attributes applied to the class appear to be wrong.
http://blogs.msdn.com/b/codeanalysis/archive/2007/04/27/correct-usage-of-the-compilergeneratedattribute-and-the-generatedcodeattribute.aspx
"CompilerGenerateAttribute - This attribute is for compiler use only and indicates that a particular code element is compiler generated. This should never be used in source code whatsoever."
"GeneratedCodeAttribute - This attribute is for use by custom tools that generate code. It should only be applied to code that is re-generated over and over and should not be used by templates that the user is expected to modify. Nor should it be applied at the type level if the type being generated is a partial class. In this situation, it should be applied only against the individual members that are contained within the generated part of the type."
Update
I've raised a bug report for this on the Microsoft Connect site and will update, and accept an answer when we get some more information http://connect.microsoft.com/VisualStudio/feedback/details/634692/publicsettingssinglefilegenerator-code-fails-when-treat-warnings-as-errors-is-set-to-all-and-xml-documentation-is-on
There's no good way to do this, you can't inject the #pragma warning disable in the auto-generated file. Also a problem with Winforms designer files btw. Project + Properties, Build tab, Suppress warnings = 1591. But that will disable the diagnostic also where you might want it turned on. A #pragma warning restore doesn't fix that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With