In a project I have a bad file, and I’d like to keep it. I know, I can use “Exclude from project”, but this hides the file (in VS 2010, in VS 2008, it was still visible). But instead, I clicked, under properties, Build Action: None. When I compile, the project compiles, but when I look in the error list, it still shows the errors of this file.
Shouldn’t the reported errors exclude the errors of files that have been excluded from the build? I.e., files marked Content are never build. But when a *.cs file is Content, the Error List still shows the errors of this file. This is more than just a nuisance. On large projects, many errors and warnings arise from files that are never compiled, obscuring the errors that matter . What can I do to prevent this?
The file is actually excluded from build, but not from the background compilation in the IDE that produces the errors in the error list1.
The simplest thing is to comment out the entire file, press
Ctrl+Ato select everything, and theCtrl+K, Cto comment out the file.Another option is to use conditional compilation. On top of your source file insert an undefined pre-compiler constant:
Yet another option, of course, is to rename the file so that it has a different extension, e.g. .txt. This will make you loose all the IDE features related to C# such as syntax highlighting though.
1You will actually see that the error list contains less errors (as far as I can see only syntax errors) when you set the Build Action to something other than Compile