Razorlight: PrecompiledViews - RazorLight in Production

Created on 16 Mar 2018  路  3Comments  路  Source: toddams/RazorLight

I thought I would ask this here, since it will help others.

Apparently in .NET Core 2, at least when using App Services and Web Deploy, razor views are not deployed directly via the file system, as .cshtml files. Rather, it seems they are packaged into a DLL called [Project].PrecompiledViews.dll ... If you are using UseFilesystemProject(), this leads to problems the first time you leave development and deploy to a server.

I am currently trying to figure out how to work around this. I've tried:

  • Setting the build action for my views to Content > Copy Always
  • Searching for ways to use RazorLight with PrecompiledViews rather than the file system

Rather than iterate all the possibilities for solving this, it's probably best to just ask: am I missing something, and what's the best practice for a simple case like this?

Thanks for the great project, I appreciate you. :)

Most helpful comment

Thank god for this question. I would indeed really recommend that you (@Gerfaut) add the following note under the "File source" section of your readme:

As of ASP.NET Core 2.0 you need to make sure the views are included in the publish by adding the following to your project.csproj file, otherwise it wont normally be included in your published/production environment.

<PropertyGroup>
  <MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
</PropertyGroup>

All 3 comments

Hi @kinetiq,

As workaround you can also use
<MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
in web.config to avoid View precompilation on publish.

Although this is only a workaround for now...

Source: https://neelbhatt.com/2017/08/27/razor-pages-compilation-on-publish-a-net-core-2-0-feature/

Thank you for the response. Please put this in the docs for others, I spent over 4 hours on this. :)

Thank god for this question. I would indeed really recommend that you (@Gerfaut) add the following note under the "File source" section of your readme:

As of ASP.NET Core 2.0 you need to make sure the views are included in the publish by adding the following to your project.csproj file, otherwise it wont normally be included in your published/production environment.

<PropertyGroup>
  <MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
</PropertyGroup>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Eonasdan picture Eonasdan  路  6Comments

Wolftousen picture Wolftousen  路  5Comments

btran021111 picture btran021111  路  4Comments

xxeasterxx picture xxeasterxx  路  5Comments

danwalmsley picture danwalmsley  路  7Comments