Last active
April 18, 2020 21:25
-
-
Save ankittyagii/6e4a933839485efb9c663bb1ecc19a41 to your computer and use it in GitHub Desktop.
Razor Runtine Compilation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#By default in asp.net core 3.0 razor views runtime compilation is disabled . See why and how we need to enable this razor runtime compilation | |
#After we enable the runtime compilation we need not to recompile the program again. By saving and refreshing the browser we can easily see the new changes. | |
#How to overcome from this problem. | |
#Solution - You need to install the nuget package i.e | |
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation | |
#1. For all environment. | |
#Go to startup file - | |
using Microsoft.AspNetCore.Mvc.Razor.Runtime; | |
# ConfigureServices method | |
#add the below code | |
services.AddMVC().AddRazorRuntimeCompilation(); | |
#Or | |
services.AddRazorPages().AddRazorRuntimeCompilation(); | |
#2. Conditionally Enable for Debug environment | |
#Edit the .csproj file add the following code | |
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.0" Condition="'$(Configuration)' == 'Debug'" /> | |
#if you want to condionally defined then the below line of code in configureservices method of startup | |
public IWebHostEnvironment Env { get; set; } | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
IMvcBuilder builder = services.AddRazorPages(); | |
#if DEBUG | |
if (Env.IsDevelopment()) | |
{ | |
builder.AddRazorRuntimeCompilation(); | |
} | |
#endif | |
} | |
#Happy Learning | |
#anvitte #anvitteaspnetcore #aspnetcore #opensourceplatform #razorruntimecompilation #configuration #aspnetcore3dot0 #anvittecsharp #learning #knowledgesharing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment