'Visual Studio for Mac 2022 - Hot Reload?
I am a fairly new to developing applications on Mac OS. I am using Visual Studio for Mac 2022 - Preview. I am all up to date and have created a ASP.NET MVC Web Application using .NET 6. I have started the debugger using the generated project. I make a change to the Index.cshtml file but that change fails to be reflected in the browser after saving the file. Any ideas if Hot Reload works in Visual Studio for Mac? I dont see any button to toggle the Hot Reload as all screenshots i have seen are for Windows Visual Studio. Any help would be appreciated as stopping and starting the debugger each time a change is made is very inconvenient. Thanks.
EDIT: I have installed the Nuget Package
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
And then updated my Program.cs file as follows:
// Add services to the container.
builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();
My changes to .cshtml files still do not want to recompile after saving.
Any more help would be appreciated.
Visual Studio for Mac Version: 17.0 Preview (17.0 build 5186)
Created a new Web Application (Model-View-Controller) project.
Solution 1:[1]
I don't know of any way to do it within Visual Studio, but if you navigate to the folder with your .csproj in Terminal, you can type
dotnet watch
and it will load your app. Then you can make changes within Visual Studio, save, and the browser will automatically reload. The only problem is since it's running from the command line, it won't hit breakpoints in your program (I don't know of any way to do so anyway).
Solution 2:[2]
I got it to work on the latest preview version of Visual Studio 2022 for Mac. You will need to add the NuGet package, and also add the service to your builder in the program.cs
file as an extra service:
builder.services.AddRazorPages().AddRazorRuntimecompilation();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | bburgess |
Solution 2 | Jeremy Caney |