How to make the Visual Studio compiler ignore a fi

2019-01-23 17:54发布

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.

4条回答
ゆ 、 Hurt°
2楼-- · 2019-01-23 18:09

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

查看更多
贼婆χ
3楼-- · 2019-01-23 18:21

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.

查看更多
来,给爷笑一个
4楼-- · 2019-01-23 18:23

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.

查看更多
聊天终结者
5楼-- · 2019-01-23 18:32

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

查看更多
登录 后发表回答