Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the Visual Studio compiler ignore a file?

Is anyone aware of a way to make visual studio completely ignore a file when compiling? I have a C# solution that has a foo.config file that isn't really a standard config file - it's just a text file. During compiling VS grabs a hold of the file and bombs.

I'd like for it to act as though it's just a text file. I do not have the option of changing the name of the file.

EDIT: Please note that BuildAction does not exclude files from the compiler checking them. It simply decides if the file is compiled into the assembly, whether it's content (like a jpg or something), or whether it is a resource file. For more info: see the MSDN page.

EDIT2: Apparently, if you have a text file that is named foo.config and you have it open while building, VS2005 will pop up an error thinking that the file should be xml. However, if you close the file, VS2005 will ignore it.

Solution: Visual Studio validation causes errors if you have a non-compliant file open during build time. For an example of how to turn this off (for HTML), see Scott Guthrie's post. As Allen mentioned, you should also have the Build Action turned to "None". Unfortunately, this will not stop build errors if you have the file open.

like image 771
VanOrman Avatar asked Mar 05 '09 14:03

VanOrman


2 Answers

right click > properties

Build Action: set to "None"

Edit: If you're talking about app.config, you really cant mess with the format of that, you need to put it in a different .config file.

I just double checked, VS.net doesnt care as long as its not app.config or web.config and the config file build action is set to "None", it will "error" if you have the file open but it will not cause the build to fail or keep it from building the assemblies.

Close the file and the errors will go away, similar to the errors you get about HTML markup. The displaying of these "errors" is probably a configurable setting in vs.net

like image 111
Allen Rice Avatar answered Oct 19 '22 05:10

Allen Rice


The action to take depends on the solution and and file type. For instance (in VS2005), in a C++ solution I can right click on the source file name in the solution explorer and view its properties. The first "General" option is "Excluded From Build", which will allow you to exclude the file from the build process without having it excluded from the project altogether.

I pulled up a .config file in a C# solution, and found a "Build Action" option under the Advanced section. That should probably be set to "None".

like image 33
zweiterlinde Avatar answered Oct 19 '22 05:10

zweiterlinde