Publish the Views with asp.net core

Viewed 12334

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?

3 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();

And also you need to install '.Net Core hosting bundle for IIS' before publishing your site.

Related