'dotnet watch run -c $(Configuration) with hot reload
I want to launch my Blazor app with specific configuration and have hot-reload enabled.
When I launch with:
dotnet watch
Hot reload is enabled and everything it's ok.
When I lanch with:
dotnet watch run -c Simulation
Hot reload is not active and the app rebuild when a file is changed.
I have try to launch with:
dotnet watch -c Simulation
But it's return "watch : Exited with error code 1".
How launch my app with wanted configuration and hot-reload ?
EDIT:
My launch profile from launchSettings.json file:
"Dotnet Watch": {
"commandName": "Executable",
"executablePath": "C:\\Program Files\\dotnet\\dotnet.exe",
"commandLineArgs": "watch run -c $(Configuration)",
"hotReloadProfile": "aspnetcore",
"workingDirectory": "$(ProjectDir)",
"launchUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
Adding "hotReloadProfile": "aspnetcore" doesn't work.
And my dotnet version is :
6.0.300-preview.22154.4
EDIT2:
Temporary I use environment variable and not project configurations to switch between Simulation profile and others, but it's strange to not have any solution's to have hot reload with a specific profile. Nothing on the web about that.
Solution 1:[1]
According to this article, the way to go is to add "hotReloadProfile": "aspnetcore"
to your launchSettings.json
like so:
{
"profiles": {
"dotnet": {
"commandName": "Project"
}
}
}
And debug your app using dotnet watch run
command.
Edit:
As of dotnet sdk version 6.0.300-preview.22204.3
this issue has been addressed and the configuration shown at your first edit works with both Visual Studio and JetBrains Rider. Tested on a vanila project with a new dummy configuration called Simulation
copied directly from debug.
That said, it seems like dotnet cli
cannot call this launch profile
PS P:\Path\To\Project> dotnet run --launch-profile "Dotnet Watch"
The launch profile "Dotnet Watch" could not be applied.
The launch profile type 'Executable' is not supported.
My Full launchSettings.json
:
{
"profiles": {
"HotRelaodTests": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Dotnet Watch": {
"commandName": "Executable",
"executablePath": "C:\\Program Files\\dotnet\\dotnet.exe",
"commandLineArgs": "watch run -c $(Configuration)",
"workingDirectory": "$(ProjectDir)",
"launchUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
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 |