dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.85k stars 667 forks source link

Unable to configure commandline args with help #6916

Open richlander opened 6 months ago

richlander commented 6 months ago

I was unable to figure out how to enable command line args using this page: https://code.visualstudio.com/docs/csharp/debugger-settings

I asked Bing Copilot and it gave me the answer I wanted with copy/paste syntax right away. It gave me a helpful explanation, plus the following JSON.

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "coreclr",
            "request": "launch",
            "name": "Debug MyApp",
            "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/MyApp.dll",
            "args": ["arg1", "arg2", "arg3"]
        }
    ]
}

Prompt: "how do I specify command line arguments in vs code launch.json for C#?"

gregg-miskelly commented 6 months ago

@richlander was the issue that you didn't have a launch.json starting point? Or that the docs don't really spell out an example?

FYI --

  1. The recommended way to do this is with launchSetting.json rather than launch.json, though we don't currently have a great gesture to set this up :(
  2. The copilot-generated example, is not great -- I hope your app isn't targeting .NET Core 3.1, and it doesn't have a build task
  3. If you do want to generate a launch.json and you have Dev Kit installed, the best way to do so is by running '.NET: Generate Assets for Build and Debug' from the command pallet. I think we should at least add a 'Setting up launch.json' section to the top of https://code.visualstudio.com/docs/csharp/debugger-settings with this information.
stewartadam commented 3 months ago

+1 the docs and instructions on this are not clear. For example the docs page linked by Richard says:

With C# Dev Kit, you can bring your launchSettings.json from Visual Studio to work with Visual Studio Code

Okay, but where does that launchSettings.json configuration file go? ${workspaceFilder}/Properties/launchSettings.json? Or maybe ${workspaceFolder}/${PATH_TO_PROJECT_FOLDER}/Properties/launchSettings.json?

The docs page will show config snippets (e.g. launchbut often omit where that snippet needs to go, which is important when we're talking about 3 different config files. For example:

To configure which launchSettings.json profile to use (or to prevent it from being used), set the launchSettingsProfile option: "launchSettingsProfile": "ProfileNameGoesHere"

So launchSettingsProfile is a member of the debug configuration entry under launch.json, or a property at the top-level of launchSettings.json to select which of its member profiles to use?

stewartadam commented 3 months ago

In addition, the experience for generation launch configurations is confusing and the new approach seems undocumented.

The docs appear to reference the older coreclr type launch configuration but if I go into launch.json myself and click "Add configuration..." and then select "C#", it adds a new dotnet configuration centered around a csproj file:

{
      "name": "C#: <project-name> Debug",
      "type": "dotnet",
      "request": "launch",
      "projectPath": "${workspaceFolder}/<relative-path-to-project-folder><project-name>.csproj"
    },

No more hardcoding of DLL paths! Excellent. Not so excellent is apparently all the other usual config parameters like env, cwd, args, etc are gone and no longer work. Trying to pick a launch settings profile name or settings location also fails.

There's also the new Dynamic Configurations which work great but they use a launchConfigurationId property whose syntax I can't seem to find documented anywhere. It also appears to have no effect; launchSettings.json is entirely ignored and the syntax in launchConfigurationId doesn't change the executed debug server (which I verified by setting the console to external terminal).