I’m looking to enable Hot Reload to hopefully allow edits to *.cs
and/or *.cshtml
files without restarting debug cycle.
My original configurations in tasks.json
and launch.json
are as follows and everything worked (without Hot Reload)…after the site built and started, it found the log entry in terminal and launched the site with the uriFormat
argument in a new/clean Chrome instance and all debugging working as expected.
Original tasks.json
:
{
"label": "debug",
"hide": true,
"command": "dotnet",
"type": "process",
"presentation": {
"clear": true
},
"args": [
"build", "${input:projectFile}",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
Original launch.json
:
{
"name": "Site",
"presentation": {
"order": 1,
"group": "1. L@W Connect"
},
"type": "coreclr",
"request": "launch",
"preLaunchTask": "debug",
"logging": {
"moduleLoad": false
},
"program": "${workspaceFolder}/bin/Debug/net7.0/Nexgen.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"serverReadyAction": {
"action": "debugWithChrome",
"pattern": "\bNow listening on:\s+(https?://\S+)",
"uriFormat": "%s/app/channel-home?aws=1&lp=0&datasource=1&showinspector=1&apidebug=ApiProxy_,RBLe_,DocGen_&rblcache=1&tracekatapp=0&sitekey=GOLD",
"killOnServerStop": true
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
},
"launchSettingsProfile": "Site"
},
I modified these files (with advice from Github Copilot) with the following.
New tasks.json
:
- New
label
- New
args
- Added
isBackground
- New
presentation
settings
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${input:projectFile}"
],
"problemMatcher": "$msCompile",
"isBackground": true,
"presentation": {
"reveal": "always",
"panel": "shared"
}
}
New launch.json
:
serverReadyAction.action
andserverReadyAction.uriFormat
changed- Removed
launchSettingsProfile
(which is used by devs in Visual Studio proper)
{
"name": "Site",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "watch",
"program": "${workspaceFolder}/bin/Debug/net7.0/Nexgen.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "Now listening on: (https?://\S+)",
"uriFormat": "%s"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
When I try to launch with updated settings, I get a dialog stating (even though there is a problemMatcher
defined):
The task ‘watch’ has not exited and doesn’t have a ‘problemMatcher’ defined. Make sure to define a problem matcher for watch tasks.
[Debug Anyway] [Configure Task] [Cancel]
In the terminal window, my logging is as follows:
dotnet watch 🔥 Hot reload enabled. For a list of supported edits, see https://aka.ms/dotnet/hot-reload. 💡 Press "Ctrl + R" to restart.
dotnet watch 🔧 Building...
Determining projects to restore...
All projects are up-to-date for restore.
Camelot.Abstractions.Api.Contracts.WebService.Proxy -> c:BTRCamelotAbstractionsApi.ContractsWebService.ProxysrcbinDebugnet7.0KAT.Camelot.Abstractions.Api.Contracts.WebService.Proxy.dll
Camelot.Abstractions.Api.Contracts.DataLocker -> c:BTRCamelotAbstractionsApi.ContractsDataLockersrcbinDebugnet7.0KAT.Camelot.Abstractions.Api.Contracts.DataLocker.dll
Camelot.Abstractions.RBLe -> c:BTRCamelotAbstractionsRBLebinDebugnet7.0KAT.Camelot.Abstractions.RBLe.dll
Camelot.Abstractions.Api.Contracts.RBLe -> c:BTRCamelotAbstractionsApi.ContractsRBLesrcbinDebugnet7.0KAT.Camelot.Abstractions.Api.Contracts.RBLe.dll
Camelot.Domain -> c:BTRCamelotCoreDomainsrcbinDebugnet7.0KAT.Camelot.Domain.dll
Camelot.Infrastructure -> c:BTRCamelotCoreInfrastructuresrcbinDebugnet7.0KAT.Camelot.Infrastructure.dll
Camelot.Telemetry -> c:BTRCamelotCoreTelemetrysrcbinDebugnet7.0KAT.Camelot.Telemetry.dll
Camelot.Data -> c:BTRCamelotCoreDatasrcbinDebugnet7.0KAT.Camelot.Data.dll
Camelot.Domain.Web -> c:BTRCamelotCoreDomain.WebsrcbinDebugnet7.0KAT.Camelot.Domain.Web.dll
Camelot.Telemetry.Web -> c:BTRCamelotCoreTelemetry.WebsrcbinDebugnet7.0KAT.Camelot.Telemetry.Web.dll
Camelot.Infrastructure.Web -> c:BTRCamelotCoreInfrastructure.WebsrcbinDebugnet7.0KAT.Camelot.Infrastructure.Web.dll
Nexgen -> c:BTRCamelotWebsitesNexgenbinDebugnet7.0Nexgen.dll
dotnet watch 🚀 Started
[22:24:28 INF] Now listening on: https://localhost:7058 <s:Microsoft.Hosting.Lifetime>
dotnet watch 🌐 Unable to launch the browser. Navigate to https://localhost:7058 <s:Microsoft.Hosting.Lifetime>
[22:24:28 INF] Application started. Press Ctrl+C to shut down. <s:Microsoft.Hosting.Lifetime>
[22:24:28 INF] Hosting environment: Development <s:Microsoft.Hosting.Lifetime>
[22:24:28 INF] Content root path: c:BTRCamelotWebsitesNexgen <s:Microsoft.Hosting.Lifetime>
How can I enable Hot Reload?
2
In VS code you can open the terminal and run command “dotnet watch run” which will provide you similar functionality.
You can reference this issue: ASP.NET Core with VS Code, can’t run the application without debugging enabled
2