In Visual Studio 2019, I can debug a .NET Core console application with command line arguments using a configuration similar to below in launchSettings.json
.
{
"profiles": {
"MyConsoleApp": {
"commandName": "Project",
"commandLineArgs": "-a -v"
}
}
}
I would like to be able to debug this using Visual Studio Container Tools inside of a Docker container. I added another build profile to launchSettings.json
as follows:
{
"profiles": {
"Docker": {
"commandName": "Docker",
"commandLineArgs": "-a -v"
},
"MyConsoleApp": {
"commandName": "Project",
"commandLineArgs": "-a -v"
}
}
}
This successfully builds and runs the console application per the defined Dockerfile
, however the docker run
command does not include the values specified in commandLineArgs
in the Docker
profile of launchSettings.json
.
The generated docker run
command (notably without -a -v
):
docker run -dt -v "C:\Users\MyUser\vsdbg\vs2017u5:/remote_debugger:rw" -v "C:\Users\MyUser\source\repos\MyConsoleApp\src\MyConsoleApp:/app" -v "C:\Users\MyUser\.nuget\packages\:/root/.nuget/fallbackpackages2" -v "C:\Program Files\dotnet\sdk\NuGetFallbackFolder:/root/.nuget/fallbackpackages" -e "DOTNET_USE_POLLING_FILE_WATCHER=1" -e "ASPNETCORE_ENVIRONMENT=Development" -e "NUGET_PACKAGES=/root/.nuget/fallbackpackages2" -e "NUGET_FALLBACK_PACKAGES=/root/.nuget/fallbackpackages;/root/.nuget/fallbackpackages2" --entrypoint tail myconsoleapp:dev -f /dev/null
Question:
How can I pass command line args to a Docker debugging run of a .NET Core console application in Visual Studio Container Tools?
Update:
Just stumbled on this.
When I add something like this to my project file:
<DockerDebuggeeArguments>-a -v</DockerDebuggeeArguments>
The console app fails to debug at all with the following message:
-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.
The program 'dotnet' has exited with code 145 (0x91).
I have Microsoft .NET Core SDK 2.2.301 (x64)
installed.
If I exclude the DockerDebuggeeArguments
value, I can debug in Docker, but no command line arguments are passed in.
It turns out the correct solution is adding the below line to the .csproj
file:
<DockerDebuggeeArguments>-a -v</DockerDebuggeeArguments>
However, there is a bug right now that does not allow that to work.
Some workarounds for the moment:
I've identified a bug in our code preventing this scenario from working as intended. I've identified some possible workarounds:
- If you're using Linux containers, try setting the following MSBuild properties, to pass in
-a -v
to your application:
<DockerDebuggeeArguments>--additionalProbingPath /root/.nuget/fallbackpackages2 --additionalProbingPath /root/.nuget/fallbackpackages "bin/$(Configuration)/$(TargetFramework)/$(AssemblyName).dll" -a -v</DockerDebuggeeArguments>
<DockerDebuggeeProgram>/usr/bin/dotnet</DockerDebuggeeProgram>
- For Windows containers:
<DockerDebuggeeArguments>--additionalProbingPath c:\.nuget\fallbackpackages2 --additionalProbingPath c:\.nuget\fallbackpackages "bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).dll" -a -v</DockerDebuggeeArguments>
<DockerDebuggeeProgram>C:\Program Files\dotnet\dotnet</DockerDebuggeeProgram>
- For either Windows or Linux containers, if it's an option, you can change your code to use environment variables instead of command-line arguments
via @bwateratmsft
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With