Background
I’m working on a small coding project that is going to be sold to other companies. I needed to create some documentation for it, so I decided to use Sandcastle. After taking far to long to download and install, I finally got it working, and noticed any public method or class that didn’t have a comment had red text stating that the comment was missing. I then installed Ghostdoc to help speed up my commenting. This turned on the compiler warnings for missing xml comments, which was great because I now had a list of everything I needed to comment.
The Problem
One of my code files is an auto-generated file, which contains around 3000 compiler warnings. I need to be able to skip that file from creating any “Missing Xml Comment” compiler warnings. I know these things from this post:
- I know I can turn off the compiler warning for the project, but there are other files in the project that should have the compiler warning.
- I know I can use
#pragma warning disable 1591to remove the compiler warning, but the file is autogenerated, and I really don’t want to have to re-add it manually every time. - I know I can add an empty comment, but once again, I really don’t want to have to re-add it every time the file gets regenerated.
- I could pull the file out into it’s own project since it is the only class in it’s namespace, then remove the XML comment requirement, but I don’t want the customer to have to deal with another dll.
- The classes are partial classes so I was thinking about trying to find a way to add the #pragma warning disable in a partial class but even if that was possible, there are still enums that would throw warnings.
How can I tell VS to ignore a single file for a particular type of warning?
Edit: My Solution
I used David Thielen’s suggestion and created a C# program that inserts
#pragma warning disablemessages into my autogenerated files. Ideally I’d call it as a post operation to the generation of the files themselves, but for now a pre-compile command will suffice since my statement will be one of the first lines in the file, it will only have to read a few lines, see that the disable statement is already there, and quit, so it shouldn’t slow down the build. Below is my program for all to enjoy! 🙂