I use VS 2022, and I am working on an ASP.NET Core MVC project, .NET version 7. Hot reload feature pretty much never works. When I restart VS, it sometimes decides to work for a while, but breaks again quickly anyway. Clicking the hot reload icon inside VS (the red flame button next to the "start" button) does not help, because it just says "no changes detected". Because it sometimes works, it seems to me like this is a VS bug, and that the feature is simply unstable. I found this reddit thread where people complain about the same thing: https://www.reddit.com/r/csharp/comments/vcq3y0/anyone_else_having_huge_problems_with_vs_2022_and/ Wanted to ask if anyone found a way to deal with the instability, because it really slows me down having to restart app for front-end changes to be reflected.
I found that the solution is not to rely on Visual Studio's built-in hot reload, and to instead use dotnet watch
command manually, because it is much more reliable, and it simply works. To do this, open CMD, change directory to your project, and run the command.
You can also use the terminal window inside VS ("ctrl + `", or "View > Terminal"), but it may ask you to specify which project to use, as the terminal will run at the root level of the solution, so the command would have to be; dotnet watch --project NameOfYourProject
Note that it picks the first launch profile by default, so you have to either specify which profile you want to use with a parameter, or reorder the launch profiles that are defined in your "Properties/launchSettings.json" file (the launch profiles are listed under the "profiles" section in this json file). In my case, I needed to use the "https" profile, so I moved it above the "http" profile so that it is at the top.
In the profile definition, if "launchBrowser" is set to "true", dotnet watch command will also automatically launch the browser to display the hosted url. If you don't prefer this default behavior, you can set it to false. It is also possible to disable auto-refreshing of the browser, and so on. See here for a full list of options.