asp.net-mvc 运行时错误没有为扩展“.cshtml”注册的构建提供程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15330712/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 02:38:24  来源:igfitidea点击:

Runtime error there is no build provider registered for the extension '.cshtml'

asp.net-mvc

提问by Nigel

I get the following error when I try to run one of my scaffolded views in mvc 4:

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

Server Error in '/' Application. There is no build provider registered for the extension '.cshtml'. You can register one in the section in machine.config or web.config. Make sure is has a BuildProviderAppliesToAttribute attribute which includes the value 'Web' or 'All'.

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

The only answers I have found relate to intellisense but my code complies fine and breaks at runtime. This is a strange error as I am not using a class library. There is just one controller that gives this message on all of its views, all other controllers/views work fine.

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

回答by DrakonHaSh

This solved the problem for me.

这为我解决了这个问题。

Change this in Web.config

把这个改成 Web.config

<compilation debug="true" targetFramework="4.5.1" optimizeCompilations="true" />

to

<compilation debug="true" targetFramework="4.5.1" optimizeCompilations="false" />

ADDED: when after a few minutes I back web.config to old, the problem not repeated. strange things )

添加:几分钟后我将 web.config 恢复到旧时,问题不再重复。奇怪的事情 )

回答by Fuzzybear

If the solution in Razor Compiler Warning/Errors - ASP.NET MVC 4did not work by adding the following code to the ROOT web.config

如果Razor Compiler Warning/Errors - 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>

then try restarting Visual Studio. This worked for me, so would suggest that perhaps a Visual Studio bug.

然后尝试重新启动 Visual Studio。这对我有用,因此建议可能是 Visual Studio 错误。

回答by Lathejockey81

I got this error on deployment (of a previously working site) after updating to VS2013 RC2. Luckily I had other sites to compare the bin folder to - it turns out several libraries were previously deploying and magicallystopped, including the razor libraries. I changed their references Copy Localproperties to Trueand it was all better. The 3 razor libraries in question were:

更新到 VS2013 RC2 后,我在部署(以前工作的站点)时遇到此错误。幸运的是,我有其他站点可以将 bin 文件夹与其他站点进行比较 - 原来有几个库之前已经部署并神奇地停止了,包括 razor 库。我将他们的引用Copy Local属性更改为True,一切都变得更好了。有问题的 3 个剃刀库是:

  • System.Web.Razor
  • System.Web.WebPages.Deployment
  • System.Web.WebPages.Razor
  • 系统.Web.Razor
  • 系统.Web.网页.部署
  • 系统.Web.网页.Razor

I also lost the libraries whose namespaces are referenced in the web.config file, so be sure to set those to copy local as well.

我还丢失了名称空间在 web.config 文件中引用的库,因此请务必将它们也设置为复制本地。

I suspect it may be possible to resolve this on the server using the GAC, but I don't know a lot about the server side of things, so that is for another time.

我怀疑有可能使用 GAC 在服务器上解决这个问题,但我对服务器端的事情了解不多,所以这是另一个时间。

回答by rohancragg

I fixed a similar issue - documented here: https://naa4e.codeplex.com/workitem/1

我修复了一个类似的问题 - 记录在这里:https: //naa4e.codeplex.com/workitem/1

The solution was that I deleted references and re-added NuGet packages.

解决方案是我删除了引用并重新添加了 NuGet 包。

The issue seems to be that the project originally referenced MVC4 which I guess was located somewhere on the local machine (i.e. was not a NuGet Package). I simply 'restored' the package which did not properly overwrite the project reference from 4 to 5.

问题似乎是该项目最初引用了 MVC4,我猜它位于本地机器上的某个地方(即不是 NuGet 包)。我只是“恢复”了没有正确覆盖从 4 到 5 的项目引用的包。

回答by user1855805

Click 'Rebuild Solution' is enough to me

单击“重建解决方案”对我来说就足够了

回答by alexander helsinghof

I fixed this issue by changing the .Net Framework from my current version "4.52" to "4.6". You can change this if you right click on your project -> Properties then "Target Framework" After changing the current Framework, I rebuild and everything worked fine.

我通过将 .Net Framework 从当前版本“4.52”更改为“4.6”来解决此问题。如果您右键单击您的项目-> 属性,然后单击“目标框架”,您可以更改此设置。更改当前框架后,我重建并且一切正常。

After this I switched back to my current Framework version and it now works. I really don't understand why this occurs but that helped for me.

在此之后,我切换回我当前的框架版本,它现在可以工作了。我真的不明白为什么会发生这种情况,但这对我有帮助。

回答by Kapila Perera

I tried by restart IIS, removed Temporary Internet Files and changing the compilation tag in the web config file. None of them work for me.

我尝试通过重新启动 IIS,删除 Internet 临时文件并更改 Web 配置文件中的编译标记来尝试。他们都没有对我来说有效。

I fixed the issue by removing and adding System.Web.MVC to the project.

我通过删除 System.Web.MVC 并将其添加到项目中来解决该问题。

回答by Benjamin Freitag

The issue may be related to the JIT-compiler in ASP.Net. We just had this error on a productive server after we changed a single .cshtml file at runtime and didn't get the application to work again. Restarting the web-application and recycle IIS Application Pool didn't help.

该问题可能与 ASP.Net 中的 JIT 编译器有关。我们在运行时更改了单个 .cshtml 文件并且没有让应用程序再次运行后,我们只是在生产服务器上遇到了这个错误。重新启动 Web 应用程序并回收 IIS 应用程序池没有帮助。

Just for testing I changed the targetFramework="4.0"to another version and it immediately worked again. After I changed it back to the initial version-number it also worked again. I guess this change causes a complete rebuild of any Asp.Net Temporary files.

只是为了测试,我将其更改targetFramework="4.0"为另一个版本,它立即再次起作用。在我将其改回初始版本号后,它也再次运行。我猜这个更改会导致任何 Asp.Net 临时文件的完全重建。

dnn2sxc

dnn 2sxc