在 Visual Studio 容器工具中将命令行参数传递给 Docker 调试 运行 .NET Core 控制台应用程序
Pass command line args to a Docker debugging run of a .NET Core console application in Visual Studio Container Tools
在 Visual Studio 2019 年,我可以使用类似于下面 launchSettings.json
.
中的配置调试带有命令行参数的 .NET Core 控制台应用程序
{
"profiles": {
"MyConsoleApp": {
"commandName": "Project",
"commandLineArgs": "-a -v"
}
}
}
我希望能够使用 Docker 容器内的 Visual Studio 容器工具对其进行调试。我向 launchSettings.json
添加了另一个构建配置文件,如下所示:
{
"profiles": {
"Docker": {
"commandName": "Docker",
"commandLineArgs": "-a -v"
},
"MyConsoleApp": {
"commandName": "Project",
"commandLineArgs": "-a -v"
}
}
}
这根据定义的 Dockerfile
成功构建并 运行s 控制台应用程序,但是 docker run
命令不包括 commandLineArgs
中指定的值 Docker
launchSettings.json
.
的个人资料
生成的docker run
命令(特别是没有-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
问题:
如何在 Visual Studio 容器工具中将命令行参数传递给 Docker 调试 运行 .NET Core 控制台应用程序?
更新:
刚刚偶然发现 this。
当我将这样的内容添加到我的项目文件中时:
<DockerDebuggeeArguments>-a -v</DockerDebuggeeArguments>
控制台应用程序完全无法调试,并显示以下消息:
-------------------------------------------------------------------
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).
我安装了 Microsoft .NET Core SDK 2.2.301 (x64)
。
如果我排除 DockerDebuggeeArguments
值,我可以在 Docker 中进行调试,但没有传入命令行参数。
事实证明,正确的解决方案是将以下行添加到 .csproj
文件中:
<DockerDebuggeeArguments>-a -v</DockerDebuggeeArguments>
但是,现在有一个错误不允许它工作。
目前的一些解决方法:
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
在 Visual Studio 2019 年,我可以使用类似于下面 launchSettings.json
.
{
"profiles": {
"MyConsoleApp": {
"commandName": "Project",
"commandLineArgs": "-a -v"
}
}
}
我希望能够使用 Docker 容器内的 Visual Studio 容器工具对其进行调试。我向 launchSettings.json
添加了另一个构建配置文件,如下所示:
{
"profiles": {
"Docker": {
"commandName": "Docker",
"commandLineArgs": "-a -v"
},
"MyConsoleApp": {
"commandName": "Project",
"commandLineArgs": "-a -v"
}
}
}
这根据定义的 Dockerfile
成功构建并 运行s 控制台应用程序,但是 docker run
命令不包括 commandLineArgs
中指定的值 Docker
launchSettings.json
.
生成的docker run
命令(特别是没有-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
问题:
如何在 Visual Studio 容器工具中将命令行参数传递给 Docker 调试 运行 .NET Core 控制台应用程序?
更新:
刚刚偶然发现 this。
当我将这样的内容添加到我的项目文件中时:
<DockerDebuggeeArguments>-a -v</DockerDebuggeeArguments>
控制台应用程序完全无法调试,并显示以下消息:
-------------------------------------------------------------------
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).
我安装了 Microsoft .NET Core SDK 2.2.301 (x64)
。
如果我排除 DockerDebuggeeArguments
值,我可以在 Docker 中进行调试,但没有传入命令行参数。
事实证明,正确的解决方案是将以下行添加到 .csproj
文件中:
<DockerDebuggeeArguments>-a -v</DockerDebuggeeArguments>
但是,现在有一个错误不允许它工作。
目前的一些解决方法:
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