Search code examples
asp.net-coreasp.net-core-mvcazure-web-app-serviceiis-10

.NET Core MVC app not updating View unless entire project is published


I have a .NET Core MVC app hosted in IIS (development) as well as Azure App Service (production).

When I make a simple HTML change to a Razor View and publish just that view, it does not get updated.

It only gets updated if I publish the entire project.

This happens in both IIS and Azure app service.

Is this the default behavior or am I doing something wrong?

Here is the configuration page from Azure App Service:

enter image description here


Solution

  • When you publish the complete program to iis, iis compiles and runs it. .net core mvc disables runtime compilation by default, so even if the view is updated and released, the program that is already running will not compile the new view.

    If you want iis to use the new view after the VS update and release the view, you can add a line of code to the startup to enable the function of compiling and running.

    1. Add Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation Nuget package to the project.
    2. Add following code in startup.cs:

    services.AddRazorPages().AddRazorRuntimeCompilation();

    1. Publish entire project.
    2. After all of these, once you update view and publish. IIS will display new view.

    Here is my test result. enter image description here