mlst
mlst

Reputation: 3471

How to enable automatic rebuild in ASP.NET Core 2.2 when I refresh page in the browser?

This feature was working by default in ASP.NET Core 2.1 but not with the currently latest 2.2.

I've just created two basic ASP.NET Core API projects in Visual Studio 2017 (Community Edition), one with the 2.1 and other with 2.2 template. Then I run both projects with Ctrl + F5 (eg. without debugging). When I go to the /api/values url for each of them I get the default JSON. So far so good.

Now when I change ValuesController.cs in 2.1 project and hit refresh in the browser I see that it takes some time to load because web server detected changes and is rebuilding the project, and then I get the new JSON values. However, when I repeat this same process for 2.2 and hit refresh in the browser I get old values without delay (eg. no project building took place).

So how do I enable this feature in 2.2?

Upvotes: 6

Views: 2816

Answers (1)

mlst
mlst

Reputation: 3471

The solution I found is to remove or comment out <AspNetCoreHostingModel> XML node in project's .csproj file. So it looks like this:

<PropertyGroup>
  <TargetFramework>netcoreapp2.2</TargetFramework>
  <!--<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>-->
</PropertyGroup>

Now if you run ASP.NET Core application with Ctrl + F5 (without debugger) it will detect changes in .cs files and recompile at runtime as you make request that depend on new code.

Upvotes: 2

Related Questions