在 C#/VS 2010 中,如何抑制未标记为编译的文件的错误消息?
好的,我们有一个“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以:
You can:
#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).一种解决方法可能是从项目中排除该文件,并确保在 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.