Config to auto generate Views when Publish in MVC Core

 The default in NetCore Views will auto complied with .View.dll. Now with below config to set not complied Views when Publish



In Startup.CS

Add Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation if missing this DLL

public void ConfigureServices(IServiceCollection services)

        {

            //services.AddControllersWithViews();            

            services.AddControllersWithViews().AddRazorRuntimeCompilation();

}


In Project .csproj file

<PropertyGroup>

    <TargetFramework>netcoreapp3.1</TargetFramework>

    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>

    <UserSecretsId>ff68b623-c145-4e2e-af51-00254cfa2f31</UserSecretsId>

    <DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>

    <DockerfileContext>.</DockerfileContext>

    <RootNamespace>NDHN</RootNamespace>

    <AssemblyName>NDHN</AssemblyName>

<!-- add this line:-->

    <CopyRazorGenerateFilesToPublishDirectory>true</CopyRazorGenerateFilesToPublishDirectory>

    <CopyRefAssembliesToPublishDirectory>false</CopyRefAssembliesToPublishDirectory>

    <MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>

    <RazorCompileOnBuild>false</RazorCompileOnBuild>

    <!-- to this line -->

  </PropertyGroup>


Reactions

Post a Comment

0 Comments