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

发布于 2024-07-14 12:11:32 字数 745 浏览 9 评论 0原文

有谁知道如何让 Visual Studio 在编译时完全忽略文件? 我有一个 C# 解决方案,其中有一个 foo.config 文件,该文件并不是真正的标准配置文件 - 它只是一个文本文件。 在编译过程中,VS 会抓取文件并进行轰炸。

我希望它就像一个文本文件一样。 我无法选择更改文件名。

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

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

解决方案:如果在生成期间打开不兼容的文件,Visual Studio 验证会导致错误。 有关如何关闭此功能的示例(对于 HTML),请参阅 斯科特·格思里 (Scott Guthrie) 的帖子。 正如艾伦提到的,您还应该将“构建操作”设置为“无”。 不幸的是,如果您打开文件,这不会阻止构建错误。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

信仰 2024-07-21 12:11:32

右键单击> 属性

构建操作:设置为“无”

编辑:如果您正在谈论app.config,您真的不能弄乱它的格式,您需要将其放在不同的.config文件中。

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

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

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

鸢与 2024-07-21 12:11:32

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

我在 C# 解决方案中提取了一个 .config 文件,并在“高级”部分下找到了“构建操作”选项。 这可能应该设置为“无”。

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

水晶透心 2024-07-21 12:11:32

只需右键单击该文件并选择“从项目中排除”。

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

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.

泪意 2024-07-21 12:11:32

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

您应该在文件选项中检查它的“构建操作”,并且可以将其设置为“无”。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文