Visual studio WLS2 debugging and command line argument

Viewed 610

Im trying to debug a .net core console application in visual studio 2019 and WLS2. The console application requires a command line argument at startup.

This my launchSettings.json

{
  "profiles": {
    "ConsoleApp": {
      "commandName": "Project",
      "commandLineArgs": "--s",
    },
    "WSL 2": {
      "commandName": "WSL2",
      "commandLineArgs": "--s",
      "distributionName": ""
    }
  }
}

Starting the debug session with "ConsoleApp" profile the application console get the argument "--s" as expected, but executing the debug in WSL with "WSL 2" profile I get the following message:

Unknown option: --s

.NET Core SDK (3.1.404)

Usage: dotnet [runtime-options] [path-to-application] [arguments]
1 Answers

The commandLineArgs for WSL2 when not provided is defaulted to the name of the dll. When you provide one explicitly you must also provide the dll name along with the arguments. If your project name is MyNamespace.MyProject, update your launchsettings as follows:

"WSL 2": {
  "commandName": "WSL2",
  "commandLineArgs": "MyNamespace.MyProject.dll --s",
  "distributionName": ""
}
Related