Can vscode use a profile from Properties/launchSettings.json?
Asked Answered
A

2

12

Is there a way to just point ".vscode/launch.json" to a profile defined in my "Properties/launchSettings.json" so I don't need to duplicate those values?

I need to support several different editors and also run from command line with

dotnet run --launch-profile="myprofile"
Allegro answered 26/1, 2022 at 19:12 Comment(2)
Does this answer your question? Visual Studio Code: run Python file with arguments - its VsCode generic and applies to C# the same as Python or any other language.Pregnancy
This is .net specific. launchSettings.json is read by .netAllegro
A
7

This is in the docs under debugger-launchjson.md > launchSettings.json support:

"launchSettingsProfile": "${workspaceFolder}/<Relative-Path-To-Project-Directory/Properties/launchSettings.json"
Allegro answered 3/2, 2022 at 0:8 Comment(1)
This does not seem right, should it be "launchSettingsFilePath" ?Helsinki
K
1

Here is the full example. Let's assume this is your project's structure:

\.vscode
  launch.json
\src
  \YourApp
    \Properties
      launchSettings.json
    appsettings.json    
    YourApp.csproj

Part of launchSettings.json content with profile:

{  
  "profiles": {
    "Sample": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "https://localhost:7152;http://localhost:5105",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

The minimum working launch.json file content:

{
    "version": "0.2.0",
    "configurations": [        
        {
            "name": "YourApp Sample",
            "type": "coreclr",
            "request": "launch",
            "program": "${workspaceFolder}/src/YourApp/bin/Debug/net8.0/YourApp.dll",
            "cwd": "${workspaceFolder}/src/YourApp",
            "launchSettingsFilePath": "${workspaceFolder}/src/YourApp/Properties/launchSettings.json",
            "launchSettingsProfile": "Sample"
        }
    ]
}

It's important to set cwd in case if your project folder is not the same as ${workspaceFolder}. More details here.

Kendrick answered 18/5 at 12:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.