我发现如果我 Select Build Only而不是Build + IntelliSense,错误(与智能感知相关)就会消失.
Update 1: The Reason
发生这种情况的原因是,对于这样的代码:
<% if (true) { %>
<%=1%>
<% } %>
<%=2%>
In order to provide IntelliSense in <%= %> blocks at design time, ASP.NET generates assignment to a temporary __o variable and language (VB or C#) then provide the IntelliSense for the variable. That is done when page compiler sees the first <%= ... %> block. But here, the block is inside the if, so after the if closes, the variable goes out of scope. We end up generating something like this:
if (true) {
object @__o;
@__o = 1;
}
@__o = 2;
解决方法是在页面的早期添加一个伪表达式.例如.
<%=""%>
这不会呈现任何内容,并且它将确保在任何潜在的if(或其他作用域)语句之前,在Render方法中声明__o为顶级.
Update 2: Getting rid of this error without losing other IntelliSense errors
单击"错误列表"面板左上角的"过滤器"按钮,并取消选中CS0103,其中:The name '__o' does not exist in the current context的错误代码将不再显示,并且您仍然可以看到其他IntelliSense错误和警告: