joym8
joym8

Reputation: 4232

.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

Upvotes: 1

Views: 2527

Answers (2)

Bruce Zhang
Bruce Zhang

Reputation: 3042

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

Upvotes: 1

Jason Pan
Jason Pan

Reputation: 22029

You don't need to do any operations on the portal.

The article provided by Lex Li talks about the content of Razor when compiling. Simply put, C# server code can be written in the .cshtml file. After compilation, it will become projectname.Views.dll, so when you modify When the .cshtml file is not sure which projects it is associated with, it is recommended to update it globally to avoid bugs caused by version issues.

Regarding your current problem of partial update, it is also easy to solve. First, you need to define the file or folder inclusion options when compiling. You need read offical document first.

Below screenshot is my test project.

enter image description here

enter image description here

enter image description here

After my modification and settings, you can publish your customized files or folders to the azure production environment. (The code setting part is for reference only, coding according to specific projects)

In the post, you said that you want to publish an html file, then you can right-click the file or folder and select publish file or folder.

enter image description here

Right click test folder.

enter image description here

From the screenshot message below, we can see that the partial update was successful, the speed is very fast, the modified content is also prompted, and the global update is not performed.

enter image description here

prompt:

  1. The above steps are all tested and passed, and the answers and code parts given are for reference only.

  2. If you encounter problems during the operation, it is recommended to raise a support ticket on the portal.

Upvotes: 0

Related Questions