运行时错误没有为扩展名'.cshtml'注册的构建提供程序

Nig*_*gel 25 asp.net-mvc

当我尝试在mvc 4中运行我的一个脚手架视图时出现以下错误:

'/'应用程序中的服务器错误.没有为扩展名".cshtml"注册的构建提供程序.您可以在machine.config或web.config中的部分中注册一个.确保具有BuildProviderAppliesToAttribute属性,该属性包含值"Web"或"全部".

我发现的唯一答案与intellisense有关但我的代码在运行时符合要求并且中断.这是一个奇怪的错误,因为我没有使用类库.只有一个控制器在其所有视图上提供此消息,所有其他控制器/视图都正常工作.

Dra*_*aSh 50

这解决了我的问题.

改变这个 Web.config

<compilation debug="true" targetFramework="4.5.1" optimizeCompilations="true" />
Run Code Online (Sandbox Code Playgroud)

<compilation debug="true" targetFramework="4.5.1" optimizeCompilations="false" />
Run Code Online (Sandbox Code Playgroud)

补充:几分钟后我将web.config恢复到旧版,问题不再重复.奇怪的事情 )

  • 这可能是因为optimizeCompilations ="true"导致只编译了*changed*文件.如果先前的编译出现问题,除非重新编译有问题的文件,否则不会修复,直到更改为止.无论更改状态如何,设置optimizeCompilations ="false"都会导致重新编译所有内容.一旦您的网站再次运行,您可以切换回"true". (4认同)

Fuz*_*ear 15

如果Razor编译器警告/错误 - ASP.NET MVC 4中的解决方案无法通过将以下代码添加到ROOT web.config中

<compilation debug="true" targetFramework="4.0">
  <!-- New -->
  <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>
Run Code Online (Sandbox Code Playgroud)

然后尝试重新启动Visual Studio.这对我有用,所以会暗示可能是Visual Studio的bug.

  • 重新启动Visual Studio对我有用.即使我的Web.Config只有这些:System.Web.Mvc,System.Web.Abstractions,System.Web.Routing,System.Data.Linq,System.Data.Entity,System.Data.Entity.Design并且没有有:System.Web.Helpers,System.Web.WebPages (3认同)