Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 867
mlst Avatar asked Dec 21 '18 15:12

mlst


1 Answers

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.

like image 61
mlst Avatar answered Nov 15 '22 09:11

mlst