Simpliest way to configure Runtime Compilation for Local Development only is to update launch profiles in launchSettings.json
. This method requires no code changes to configure a project which is running locally (it will not affect your production).
See the official documentation:
- Install the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package.
- Modify the launch profile environmentVariables section in launchSettings.json:
- Verify
ASPNETCORE_ENVIRONMENT
is set to "Development".
- Set
ASPNETCORE_HOSTINGSTARTUPASSEMBLIES
to "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation".
Example:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:57676",
"sslPort": 44364
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
}
},
"RazorPagesApp": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
}
}
}
}
.AddRazorRuntimeCompilation();
Thank you! – Isborne