如何使Visual Studio编译器忽略文件?

时间:2022-02-16 22:26:52

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.

是否有人知道在编译时使visual studio完全忽略文件的方法?我有一个C#解决方案,它有一个foo.config文件,它不是一个真正的标准配置文件 - 它只是一个文本文件。在编译期间,VS抓住了文件和炸弹。

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.

编辑:请注意,BuildAction不会从编译器中排除检查它们的文件。它只是决定文件是否被编译到程序集中,是否是内容(如jpg或其他东西),或者它是否是资源文件。有关详细信息:请参阅MSDN页面。

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.

EDIT2:显然,如果你有一个名为foo.config的文本文件,并且你在构建时打开它,VS2005会弹出一个错误,认为该文件应该是xml。但是,如果您关闭该文件,VS2005将忽略它。

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.

解决方案:如果在构建期间打开了不兼容的文件,则Visual Studio验证会导致错误。有关如何将其关闭(对于HTML)的示例,请参阅Scott Guthrie的帖子。正如艾伦所说,你也应该将Build Action转为“None”。不幸的是,如果您打开文件,这不会停止构建错误。

4 个解决方案

#1


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.

编辑:如果你在谈论app.config,你真的不能搞乱它的格式,你需要把它放在一个不同的.config文件中。

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.

我只是仔细检查,VS.net不关心,只要它不是app.config或web.config和配置文件构建操作设置为“无”,如果你打开文件但它不会“错误”导致构建失败或阻止构建程序集。

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

关闭文件,错误将消失,类似于您获得的HTML标记错误。显示这些“错误”可能是vs.net中的可配置设置

#2


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.

要采取的操作取决于解决方案和文件类型。例如(在VS2005中),在C ++解决方案中,我可以右键单击解决方案资源管理器中的源文件名并查看其属性。第一个“常规”选项是“从构建中排除”,它允许您从构建过程中排除该文件,而不必将其从项目中排除。

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

我在C#解决方案中提取了一个.config文件,并在Advanced部分下找到了“Build Action”选项。那可能应该设置为“无”。

#3


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.

如果您仍想在项目中看到它,请选择项目,然后单击解决方案资源管理器顶部的“显示所有文件”按钮。这将显示目录树中的所有文件,即使它们实际上不是项目的一部分。

#4


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

你确定VS编译.config文件???

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

您应该在文件选项中检查它的Build Action,并且可以将其设置为none。

#1


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.

编辑:如果你在谈论app.config,你真的不能搞乱它的格式,你需要把它放在一个不同的.config文件中。

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.

我只是仔细检查,VS.net不关心,只要它不是app.config或web.config和配置文件构建操作设置为“无”,如果你打开文件但它不会“错误”导致构建失败或阻止构建程序集。

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

关闭文件,错误将消失,类似于您获得的HTML标记错误。显示这些“错误”可能是vs.net中的可配置设置

#2


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.

要采取的操作取决于解决方案和文件类型。例如(在VS2005中),在C ++解决方案中,我可以右键单击解决方案资源管理器中的源文件名并查看其属性。第一个“常规”选项是“从构建中排除”,它允许您从构建过程中排除该文件,而不必将其从项目中排除。

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

我在C#解决方案中提取了一个.config文件,并在Advanced部分下找到了“Build Action”选项。那可能应该设置为“无”。

#3


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.

如果您仍想在项目中看到它,请选择项目,然后单击解决方案资源管理器顶部的“显示所有文件”按钮。这将显示目录树中的所有文件,即使它们实际上不是项目的一部分。

#4


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

你确定VS编译.config文件???

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

您应该在文件选项中检查它的Build Action,并且可以将其设置为none。