Search code examples
web-deployment

AddRazorRuntimeCompilation causing deployment problems


When I try to deploy my project it fails with the following message:-

Startup.cs(75,25): error CS1061: 'IMvcBuilder' does not contain a definition for 'AddRazorRuntimeCompilation' 
and no accessible extension method 'AddRazorRuntimeCompilation' accepting a first argument of type 'IMvcBuilder' 
could be found (are you missing a using directive or an assembly reference?)

I found an answer here How to fix 'IMvcBuilder' doesn't contain a definition for 'AddXmlDataContractSerializerFormatters' however after installing the suggested MVC formatter package(s) The issue persisted.

The only way I have been able to deploy is to comment out the following lines in my startup class

var builder = services.AddRazorPages();
if (Env.IsDevelopment())
{
    builder.AddRazorRuntimeCompilation();
}

Maybe I need to update something on the deployment server? It is the organisation's first DotNet Core 3.1 application


Solution

  • You need to install Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation, but not the latest version. Something compatible with .Net Core 3.x.

    E.g.

    Package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation 3.1.19