0

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:

  1. New label
  2. New args
  3. Added isBackground
  4. 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:

  1. serverReadyAction.action and serverReadyAction.uriFormat changed
  2. 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:\BTR\Camelot\Abstractions\Api.Contracts\WebService.Proxy\src\bin\Debug\net7.0\KAT.Camelot.Abstractions.Api.Contracts.WebService.Proxy.dll
  Camelot.Abstractions.Api.Contracts.DataLocker -> c:\BTR\Camelot\Abstractions\Api.Contracts\DataLocker\src\bin\Debug\net7.0\KAT.Camelot.Abstractions.Api.Contracts.DataLocker.dll
  Camelot.Abstractions.RBLe -> c:\BTR\Camelot\Abstractions\RBLe\bin\Debug\net7.0\KAT.Camelot.Abstractions.RBLe.dll
  Camelot.Abstractions.Api.Contracts.RBLe -> c:\BTR\Camelot\Abstractions\Api.Contracts\RBLe\src\bin\Debug\net7.0\KAT.Camelot.Abstractions.Api.Contracts.RBLe.dll 
  Camelot.Domain -> c:\BTR\Camelot\Core\Domain\src\bin\Debug\net7.0\KAT.Camelot.Domain.dll
  Camelot.Infrastructure -> c:\BTR\Camelot\Core\Infrastructure\src\bin\Debug\net7.0\KAT.Camelot.Infrastructure.dll
  Camelot.Telemetry -> c:\BTR\Camelot\Core\Telemetry\src\bin\Debug\net7.0\KAT.Camelot.Telemetry.dll
  Camelot.Data -> c:\BTR\Camelot\Core\Data\src\bin\Debug\net7.0\KAT.Camelot.Data.dll
  Camelot.Domain.Web -> c:\BTR\Camelot\Core\Domain.Web\src\bin\Debug\net7.0\KAT.Camelot.Domain.Web.dll
  Camelot.Telemetry.Web -> c:\BTR\Camelot\Core\Telemetry.Web\src\bin\Debug\net7.0\KAT.Camelot.Telemetry.Web.dll
  Camelot.Infrastructure.Web -> c:\BTR\Camelot\Core\Infrastructure.Web\src\bin\Debug\net7.0\KAT.Camelot.Infrastructure.Web.dll
  Nexgen -> c:\BTR\Camelot\Websites\Nexgen\bin\Debug\net7.0\Nexgen.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:\BTR\Camelot\Websites\Nexgen <s:Microsoft.Hosting.Lifetime>

How can I enable Hot Reload?

2
  • ...is Hot-Reload (and/or Edit-and-Continue) actually supported by VSCode? I found postings where people say it isn't supported in VSC and you need to use the full-fat VS2022 for that. Commented Sep 11, 2024 at 5:06
  • You might be right. Github issue here. Commented Sep 11, 2024 at 13:59

1 Answer 1

0

In VS code you can open the terminal and run command "dotnet watch run" which will provide you similar functionality.

enter image description here

You can reference this issue: ASP.NET Core with VS Code, can't run the application without debugging enabled

Sign up to request clarification or add additional context in comments.

2 Comments

I get the same results...'Unable to launch the browser. Navigate to localhost:7058 <s:Microsoft.Hosting.Lifetime>'
My version is 1.93. You can try to update your version or use VS2022. Update websit:code.visualstudio.com/updates/v1_93

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.