Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publish the Views with asp.net core

Tags:

asp.net-core

In an asp.net core 2.0 project, I would like to force the publish of Views because I need them at runtime. Any clues?

like image 724
EricImhauser Avatar asked Sep 16 '17 16:09

EricImhauser


1 Answers

Joe's answer is for .Net Core 2.

In .Net Core 3, if you are using the default services.AddControllersWithViews() in your Startup.cs then you need to use RazorCompileOnPublish.

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <RazorCompileOnPublish>false</RazorCompileOnPublish>
  </PropertyGroup>

Also, if you need to enable Razor Runtime Compilation in Core 3, you require to install the "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" package, then add the AddRazorRuntimeCompilation.

services.AddControllersWithViews()
        .AddRazorRuntimeCompilation();
like image 86
Mohammad Karimi Avatar answered Sep 24 '22 08:09

Mohammad Karimi