visual-studio 如何在不显式编译的情况下让 Visual Studio 错误检查我的代码(显示波浪线)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2103952/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I get Visual Studio to error check my code (show the squiggles) without explicitly compiling?
提问by Peter Recore
I use Visual Studio (C# Express 2008) occasionally to work with some vendor supplied C# code. I am looking to make my experience with VS more like my experience with Eclipse. I have become accustomed to the way Eclipse handles underlining errors (in java source). When I make an error in my code in Eclipse, it will be underlined right away, and if I fix it, the underline will disappear almost immediately, or at worst, when I save the file. In Visual Studio however, the underline remains until I next build the project.
我偶尔使用 Visual Studio (C# Express 2008) 来处理一些供应商提供的 C# 代码。我希望让我对 VS 的体验更像我对 Eclipse 的体验。我已经习惯了 Eclipse 处理下划线错误的方式(在 java 源代码中)。当我在 Eclipse 中的代码中出错时,它会立即加下划线,如果我修复它,下划线几乎会立即消失,或者最坏的情况是,当我保存文件时。但是,在 Visual Studio 中,下划线会一直保留到我下次构建项目为止。
Is there a setting somewhere I can change so that VS will build every time I save, or even as I am typing? Is this hard to do with C# because it is more complex in some way than Java? Do I need to find someone to buy me the full (non express) version? Also, what is the squiggly underline feature called? I fear this question may have been asked before but I don't know the magic word to search for.
是否有我可以更改的设置,以便每次保存时 VS 都会构建,甚至在我打字时?这很难用 C# 做到吗,因为它在某些方面比 Java 更复杂?我需要找人给我买完整版(非快递)吗?另外,波浪形下划线功能叫什么?我担心这个问题以前可能有人问过,但我不知道要搜索的魔法词。
回答by Eric Lippert
Jason's answer is fine, but a couple additional points:
杰森的回答很好,但还有几点:
is this hard to do with C# because it is more complex in some way than Java?
这很难用 C# 做,因为它在某些方面比 Java 更复杂吗?
Yes, but that's not relevant. Yes, it is a hard problem to do on-the-fly analysis of any language in the 100 milliseconds between keystrokes. Doing it for C# is probably harder than Java, being that it supports so many more language features than Java.
是的,但这无关紧要。是的,在两次击键之间的 100 毫秒内对任何语言进行即时分析是一个难题。为 C# 做这件事可能比 Java 更难,因为它支持的语言特性比 Java 多得多。
But our IDE team is a bunch of buff coders who are awesome, so they can handle doing it for C#.
但是我们的 IDE 团队是一群很棒的编程爱好者,所以他们可以处理 C# 的工作。
The real issue was that the compiler architecture of C# was not originally designed to do this sort of analysis in realtime; the VB compiler was. And therefore it took rather longer to fix up the semantic analysis engine of the C# compiler to make this feature feasible.
真正的问题是,C# 的编译器体系结构最初并不是为实时进行此类分析而设计的。VB 编译器是。因此需要更长的时间来修复 C# 编译器的语义分析引擎,以使该功能可行。
We're continuing to do research into how to rearchitect the compiler to expose more and more of these on-the-fly analysis services in a rich, extensible and compelling way, but this will take some time. It's a big compiler.
我们正在继续研究如何重新构建编译器,以丰富、可扩展和引人注目的方式公开越来越多的这些即时分析服务,但这需要一些时间。这是一个很大的编译器。
what is the squiggly underline feature called?
波浪线下划线功能叫什么?
On the compiler team we call it "the squiggly red underline feature", or "squiggles" for short.
在编译器团队中,我们将其称为“波浪线红色下划线功能”,或简称为“波浪线”。
I don't know if marketing has a name for it or not. If they do, it's probably something like "Microsoft SquiggleSense .NET For The Microsoft Visual Studio Suite System 2008"; they seem to like these long names that have "Microsoft" in them twice.
我不知道营销是否有名称。如果他们这样做,它可能类似于“Microsoft SquiggleSense .NET For The Microsoft Visual Studio Suite System 2008”;他们似乎喜欢这些长名称中两次包含“Microsoft”的名称。
回答by jason
Do you have Visual C# 2008 Express Edition with SP1? SP1 added exactly this feature to Visual Studio 2008 Professional and Visual C# 2008 Express Edition.
你有带有 SP1 的 Visual C# 2008 Express Edition 吗?SP1 正是在 Visual Studio 2008 Professional 和 Visual C# 2008 Express Edition 中添加了此功能。
From the release notes:
从发行说明:
This service pack adds a new Visual C# IDE feature that provides a richer set of error information about your code. Specifically, this feature presents the expression-level errors that occur in open files to you according to your code. These expression-level errors were previously reported only after a build operation.
此服务包添加了一个新的 Visual C# IDE 功能,该功能提供了一组关于您的代码的更丰富的错误信息。具体来说,此功能会根据您的代码将打开文件中发生的表达式级错误呈现给您。这些表达式级错误以前仅在构建操作后报告。
From Scott Guthrie's release notes:
来自 Scott Guthrie 的发行说明:
The C# code editor now identifies and displays red squiggle errors for many semantic code issues that previously required an explicit compilation to identify. For example, if you try to declare and use an unknown type in the C# code-editor today you won't see a compile error until you do a build. Now with SP1 you'll see live red squiggle errors immediately (no explicit compile required):
C# 代码编辑器现在可以识别并显示许多以前需要显式编译才能识别的语义代码问题的红色波浪线错误。例如,如果您今天尝试在 C# 代码编辑器中声明和使用未知类型,则在进行构建之前您不会看到编译错误。现在使用 SP1,您将立即看到实时红色波浪线错误(无需显式编译):
回答by Heera
To turn this option on in VS 2010 use Tools > Options > Text Editor > C# > Advanced > Show live semantic errors and
要在 VS 2010 中打开此选项,请使用工具 > 选项 > 文本编辑器 > C# > 高级 > 显示实时语义错误和
VS 2010 use Tools > Options > Text Editor > C# > Advanced >Enter outlining mode when files open
VS 2010 使用工具 > 选项 > 文本编辑器 > C# > 高级 > 打开文件时进入大纲模式
回答by John H
To turn this option on in VS 2010use Tools> Options> Text Editor> C#> Advanced> Show live semantic errors
要在VS 2010 中打开此选项,请使用Tools> Options> Text Editor> C#> Advanced>Show live semantic errors


