在 C#/VS 2010 中,如何抑制未标记为编译的文件的错误消息?

发布于 2024-11-28 08:25:58 字数 503 浏览 0 评论 0原文

好的,我们有一个“pseudo-c#”文件,已添加到解决方案中以供参考。虽然它确实有一个 .cs 扩展名(让 VS 对其进行颜色编码,因为它相当大,这有助于提高可读性),但文件本身并未标记为使用该操作进行编译设置为“无”。

现在,当我们进行完整构建时,一切都会构建得很好,并且文件将按预期被忽略。然而,错误窗口显示了来自假代码的所有错误。我们当然可以更改扩展名来消除错误,但这样我们就会失去语法着色。

现在我假设,由于我们明确将该文件标记为“不编译”,并且由于编译器实际上忽略了错误,因此它们不会显示出来,但显然情况并非如此。

那么有人知道如何隐藏标记为从编译器中排除的文件中生成的错误吗?


更新:

由于人们不断提出解决方法,我想澄清一下,我们已经在使用解决方法。这不是我在这里追求的。我试图具体找出 VS 中是否有一些我们可以启用/禁用的设置或功能,上面写着“嘿,你没有被编译,所以你不会出现在错误列表中!”不确定是否存在这样的事情,但如果有的话,那就是我正在努力寻找的。

Ok, we have a 'pseudo-c#' file that we've added to the solution for reference. While it does have a .cs extension (to let VS take a stab at color-coding it since it's pretty big and that helps with readability) the file itself isn't marked to be compiled with the action set to 'none'.

Now, when we do a full build, everything builds just fine and the file is ignored as it's supposed to be. However, the error window is showing all the errors from the faux code. We of course can change the extension which gets rid of the errors, but then we lose syntax coloring.

Now I'd assume since we explicitly marked that file as 'do not compile' and since the errors are actually ignored by the compiler, they wouldn't show up, but obviously that isn't the case.

So anyone have any idea on how to hide errors that are generated in files that are marked to be excluded from the compiler?


Update:

Because people keep suggesting work-arounds, I want to be clear that we're already using work-arounds. That's not what I'm after here. I'm trying to find out specifically if there is some setting or feature in VS that we can enable/disable that says 'Hey, you're not being compiled so you don't get to be in the error list!' Not sure there even is such a thing, but if so, that's what I'm trying to find.

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

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

发布评论

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

评论(2

何处潇湘 2024-12-05 08:25:58

您可以:

  1. 从项目中排除该文件。右键单击有问题的文件,然后选择“排除”。要查看此文件,请选择解决方案资源管理器顶部的“显示所有文件”,然后您可以使用完整语法突出显示来编辑代码。
  2. 使用预处理器#ifdef 有条件地包含和排除代码块(或文件)。请注意,未包含的代码块不会突出显示(并检查错误)。

You can:

  1. Exclude the file from your project. Right click the file in question, and choose "Exclude". To view this file, select "Show all files" at the top of your Solution Explorer, and you can edit your code with full syntax highlighting.
  2. Use a preprocessor #ifdef to conditionally include and exclude blocks (or files) of code. Note that non-included blocks of code will not be highlighted (and checked for errors).
装迷糊 2024-12-05 08:25:58

一种解决方法可能是从项目中排除该文件,并确保在 Visual Studio 中打开“显示所有文件”。这样您就可以看到该文件,并且在打开它时仍然可以得到语法突出显示。

One workaround could be to exclude the file from the project and ensure 'show all files' is on in visual studio. That way you will be able to see the file and still get syntax highlighting when you open it.

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