剃刀智能感知错误:功能'扩展方法“不能被使用,因为它不是ISO-2 C#语言规范的一部分 [英] Razor intellisense error: Feature 'extension method' cannot be used because it is not part of the ISO-2 C# language specification

查看:284
本文介绍了剃刀智能感知错误:功能'扩展方法“不能被使用,因为它不是ISO-2 C#语言规范的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:


  • 使用CSHTML 剃须刀模板格式的数据

  • 嵌入CSHTML在类库剃须刀模板,嵌入式资源

  • 使用的LINQ 在CSHTML报表模板和扩展方法

  • Use cshtml Razor templates to format data
  • Embed cshtml Razor templates in Class Library as Embedded Resources
  • Use Linq statements and extension methods in the cshtml template

我创建了一个新的类库项目,然后改编<一个href=\"http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx\">Scott Hanselman的关于如何MVC3集成到应用程序的WebForms说明让它在类库工作。然后,我用的NuGet包RazorEngine的模板应用到一个对象。

I created a new class library project, then adapted Scott Hanselman's instructions on how to integrate MVC3 into a WebForms application to get it to work in a Class Library. Then I use the NuGet package RazorEngine to apply the template to an object.

到目前为止,它的伟大工程,一个打嗝:的IntelliSense不编辑CSHTML文件时认识的LINQ陈述或者扩展方法的(A pretty重要MVC的一部分)。

So far it works great, with one hiccup: The intellisense does not recognize Linq statements or extension methods (a pretty important part of MVC) when editing cshtml files.

所以以下CSHTML文件:

So for the following cshtml file:

@model Customer[]

@Model.Count()

@if (Model.Where(customer => customer.Type == 'New').Any())
{
    <span>Found at least one new customer.</span>
}

......它显示了以下错误:

...it displays the following errors:

特性扩展方法不能被使用,因为它不是ISO-2 C#语言规范的一部分

功能的lambda前pression'不能使用,因为它不是ISO-2 C#语言规范的一部分

有谁知道我错过了什么谢谢你在前进 - 从来就花了几个小时寻找这个问题的答案

Does anyone know what I'm missing? Thank you in advance--I've spent hours searching for the answer to this.

以下是我的的web.config 浏览文件夹:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>
  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>

  <system.web>
    <httpHandlers>
      <add path="*" verb="*" type="System.Web.HttpNotFoundHandler" />
    </httpHandlers>
    <pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <controls>
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
    </pages>
  </system.web>

  <system.webServer>  ...  </system.webServer>
</configuration>

和我添加了一个的web.config 文件到项目的根。它包含以下内容:

And I added a web.config file to the root of the project. It contains the following:

<configuration>
<system.web>
  <compilation debug="true" targetFramework="4.0">
    <assemblies>
      <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </assemblies>
  </compilation>
  ...
  <pages>
    <namespaces>
      <add namespace="System.Web.Helpers" />
      <add namespace="System.Web.Mvc" />
      <add namespace="System.Web.Mvc.Ajax" />
      <add namespace="System.Web.Mvc.Html" />
      <add namespace="System.Web.Routing" />
      <add namespace="System.Web.WebPages" />
    </namespaces>
  </pages>
</system.web>
...
</configuration>

这是项目的引用:

该类库有 .NET Framework 4的,并在高级构建设置的目标框架下,语言版本设置为 C#3.0

The Class Library has a target framework of .NET Framework 4 and under Advanced Build Settings, the Language Version is set to C# 3.0.

该项目建立并使用扩展方法和LINQ时正常运行。这只是是智能感知引发错误。

The project builds and runs properly when using extension methods and Linq. It's just the intellisense that is throws the error.

推荐答案

更​​多修修补补的几个小时后,我发现它有一些东西需要用标准的Visual Studio扩展无法正确加载。

After a couple hours more of tinkering, I found it had something to do with standard Visual Studio extensions not loading correctly.

我收到的错误:

VSTS数据库专业人士的SQL Server数据层应用程序包未正确加载

'VSTS for Database Professionals Sql Server Data-tier Application' package did not load correctly

我发现<一个答案href=\"http://connect.microsoft.com/VisualStudio/feedback/details/532121/tons-of-package-did-not-load-correctly-errors\"微软连接相对=nofollow称号=这里>。

I found the answer on on Microsoft Connect.

如何解决

1)从Visual Studio媒体运行安装程序如下:

1) Run the following installers from the Visual Studio media:

\\ WCU \\ DAC \\ DACFramework_enu.msi

\WCU\DAC\DACFramework_enu.msi

\\ WCU \\ DAC \\ DACProjectSystemSetup_enu.msi

\WCU\DAC\DACProjectSystemSetup_enu.msi

\\ WCU \\ DAC \\ TSqlLanguageService_enu.msi

\WCU\DAC\TSqlLanguageService_enu.msi

2)重新启动VS

希望这可以帮助别人。

这篇关于剃刀智能感知错误:功能'扩展方法“不能被使用,因为它不是ISO-2 C#语言规范的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆