Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8782583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:36:00+00:00 2026-06-13T20:36:00+00:00

Background I’m working on a small coding project that is going to be sold

  • 0

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 1591 to 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:36:01+00:00Added an answer on June 13, 2026 at 8:36 pm

    Edit: My Solution

    I used David Thielen’s suggestion and created a C# program that inserts #pragma warning disable messages 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! 🙂

    /// <summary>
    /// Addes #pragma warning disable messages to source code as part of a prebuild to ignore warnings.
    /// Primarly used for autogenerated classes that may contain some compiler warnings by default
    /// </summary>
    public class Program
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="args">
        /// [0] - file to edit
        /// [1] - line number to insert / edit warning disable at
        /// [2+] - warnings numbers to disable</param>
        static void Main(string[] args)
        {
            // Preconditions
            if (args.Length < 2)
            {
                throw new ArgumentException(String.Format("Unexpected number of parameters.{0}Parameters should be [0] - file to edit{0}[1] - line number to insert / edit warning disable at{0}[2+] - warnings numbers to disable", Environment.NewLine));
            }
            else if (args.Length == 2) { return; }
    
            // Valid number of args, validate arguments
            string filePath = args[0];
            long lineNumber;
    
            if(!long.TryParse(args[1], out lineNumber)){
                throw new InvalidCastException("Unable to cast \"" + args[1] + "\" to a long");
            }
    
            string[] compilerWarningNumbers = new string[args.Length - 2];
            Array.ConstrainedCopy(args, 2, compilerWarningNumbers, 0, compilerWarningNumbers.Length);
    
            // File Name and line number are valid, perform search and replace
            AddOrUpdateCompilerWarningDisabler(filePath, lineNumber, String.Join(",", compilerWarningNumbers));
    
        }
    
        private const string TEMP_FILE_POSTFIX = ".CompilerWarningDisabler.txt";
        public static void AddOrUpdateCompilerWarningDisabler(string filePath, long lineNumber, string compilerWarningNumberCSV)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException("File path not found!", filePath);
            }
    
            // Set Clear Readonly Flag
            FileInfo fileInfo = new FileInfo(filePath);
            bool isReadOnly = fileInfo.IsReadOnly;
    
            // Get Temp File Name and Delete if it already exists
            string tempFile = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + TEMP_FILE_POSTFIX);
            File.Delete(tempFile);
    
            // Read from the target file and write to a new file.
            int currentLine = 1;
            string line;
            string textToWrite = "#pragma warning disable " + compilerWarningNumberCSV;
            try
            {
                using (StreamReader reader = new StreamReader(filePath))
                using (StreamWriter writer = new StreamWriter(tempFile))
                {
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (currentLine == lineNumber)
                        {
                            if (line.StartsWith("#pragma warning disable"))
                            {
                                if (line == textToWrite)
                                {
                                    // Nothing has changed, don't bother copying file
                                    return;
                                }
                                else
                                {
                                    line = textToWrite;
                                }
                            }
                            else
                            {
                                writer.WriteLine(textToWrite);
                                writer.WriteLine(line);
                            }
                        }
                        else
                        {
                            writer.WriteLine(line);
                        }
                        currentLine++;
                    }
    
                    if (currentLine == lineNumber)
                    {
                        writer.WriteLine(textToWrite);
                    }
    
                    if (currentLine < lineNumber)
                    {
                        throw new InvalidDataException("File " + filePath + " does not contain line number " + lineNumber);
                    }
                }
    
                // This could potentially delete the source file, but this should be messing with autogenerated files, so even if it does happen, it shouldn't be to hard to get it back
                if (isReadOnly)
                {
                    fileInfo.IsReadOnly = false;
                }
                File.Delete(filePath);
                File.Move(tempFile, filePath);
                if (isReadOnly)
                {
                    new FileInfo(filePath).IsReadOnly = true;
                }
            }
            finally
            {
                File.Delete(tempFile);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: I've wrote a small library that is able to create asp.net controls from
Background: I have a CMS tool that allows users to create a table inside
Background: We're building an application that allows our customers to supply data in a
Background : I'm trying to convert some JavaScript code which uses the the Crossfilter
Background: I would like to dismiss a modalView that I have presented earlier and
Background I am working with a monad built of a stack of transformers one
Background: My employeer at my non-programming job knows that I am an undergraduate CS
Background I've got an NSOutlineView that shows TrainingGroup entities. Each TrainingGroup represents a folder
Background: I have a css and a js that is used only by the
BACKGROUND I'm writing a little game using Java, slick2d and other frameworks. Slick2d does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.