3

I'd like to be able to pass command line args to the program that is executed in a container, and also be able to debug under VS 2022 whatever the way I use (docker with launchsettings.json or docker-compose configuration profile)

The following line works nicely when I run the docker-compose command line utility outside of Visual Studio (ie the args are passed to my dot net program)

# docker-compose.yml
#...
command: [ "mycommand", "--myoption", "myvalue" ]

The following line is also taken into account and works as nicely when debugging container under VS 2022

# in launchsettings.json
#...
"commandLineArgs": "mycommand --myoption myvalue"

BUT when I try debugging using docker-compose configuration profile, the container crashes with the following error :

2023-10-27 19:50:34 tail: unrecognized option '--myoption'
2023-10-27 19:50:34 Try 'tail --help' for more information.

For reference, my docker file has this line : ENTRYPOINT ["dotnet", "myprogram.dll"]

I searched and search for a few hours and couldn't find a way to make it work.

This is very weird that the command line parameters are actually passed to the program when debugging in docker mode (launchsettings.json, docker profile, "commandLineArgs" property ), but are not taken into account when debugging in docker-compose mode (docker-compose.yml, docker-compose debug profile, "command" syntax in docker-compose.yml).

...The very same docker-compose.yml which works like a charm when run using docker-compose command line, outside VS 2022 :

docker-compose up --build --force-recreate  -d myprogram

I tried to use a docker-compose.vs.debug with no success. I tried to use the entrypoint syntax instead of the command syntax, with no success.

Edit 23/10/30 : It all comes down to the tail -f being generated by Visual Studio. I've tried many things, with docker-compose.vs.debug, and never found a way to pass parameters to my program without actually breaking everything. Every other way works fine (docker-compose command line, docker debug with launchsettings.json), but just cannot pass parameters during a docker-compose VS debug session.

1 Answer 1

3

Answering my own question to help people who would stumble on the same issue.

After a full day of research and failed attempts, I've finally found how to do it.

Create a docker-compose.vs.debug.yml file and add it to your solution.

services:
  myprogram:
    command: [] # this to void the command line parameters from docker-compose.yml
    labels:
      com.microsoft.visualstudio.debuggee.arguments: "--additionalProbingPath /root/.nuget/fallbackpackages2 --additionalProbingPath /root/.nuget/fallbackpackages [PATH_TO_YOUR_PROGRAM] [YOUR_PROGRAM_ARGUMENTS_HERE]"
      com.microsoft.visualstudio.debuggee.program: "/usr/bin/dotnet"

[PATH_TO_YOUR_PROGRAM] : Path to your dll in the container (ex : /app/bin/Debug/net6.0/myProgram.dll )

This makes the whole thing work in the 3 modes I use :

  • Docker-compose command line (using docker-compose.yml file, args are passed through "command" propery)
  • docker debug (uses launchsettings.json, args are passed through "commandLineArgs")
  • docker-compose debug (uses docker-compose.vs.debug.yml, args are passed through "com.microsoft.visualstudio.debuggee.arguments" label)

Note : the syntax will be slightly different if you use Windows containers

Sincerely hope it can help, I had a very hard time to make this simple thing work.

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

1 Comment

Hi Kinddanam, thanks for your sharing, since you have found the solution of this issue, you can mark it as the answer of this question. This will help others who encounter this issue and seeking for the solution. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.