ASP.NET MVC - Update Pre-compiled Razor View file Live in Production

一笑奈何 提交于 2019-12-04 08:08:14

Yes you can do this. The view engine will recompile all the files in each directory into a separate DLL into a file like this

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\micropedi_mvc\d3b5b4cd\eb219373\App_global.asax.ihdiifed.DLL

You can use ILSpy or Reflector to open up this file and see exactly which files were compiled to it. if you have many directories you'll see several DLLs generated.

Note that all thatMvcBuildViews` does is run this post build event which just does the same as if you were to hit each file needed for your application.

<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
   <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>

For maximum performance I'd recommend the RazorGenerator precompiler. This actually embeds the cshtml files into your main DLL which isn't what MvcBuildViews does at all. Plus its much faster.

If you wanted to use this in production you'd need to change UsePhysicalViewsIfNewer in RazorGeneratorMvcStart.cs to true so that it would recompile if you updated the view.


Tip: If you ever want to find exactly which DLL the cshtml file is compiled to just add this to your page

 <div>This file is compiled to  @this.GetType().Assembly.CodeBase</div> 

Then you'll get the full path without looking for it.

Yes, you can.

cshtml files don't get compiled like the rest of your project. So you can change them outside of your project.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!