views:

851

answers:

4

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.

+1  A: 

Just right click on the file and choose "Exclude from project".

If you still want to see it in your project, select the project and click the "Show all files" button at the top of the solution explorer. This will show all the files in the directory tree even if they aren't actually part of the project.

Eric Petroelje
+1  A: 

Are you sure that VS compiling .config file???

You should check it's Build Action in file options and may be set it to none.

Alex Reitbort
+4  A: 

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".

zweiterlinde
Is this different in VS2008? In 2005 I do not see a "General" section nor an "Exclude From Build" option.
VanOrman
It probably depends on the solution and file type. I just pulled up the properties of a config file in a C# solution, and it looks like Allen's answer may be what you want.
zweiterlinde
+8  A: 

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

Allen