简体   繁体   English

在 docker 容器中使用命令行 arguments 调试 .NET 控制台应用程序

[英]Debugging .NET console app with command line arguments within a docker container

I am debugging a .NET console application sitting within a docker container which works fine.我正在调试位于 docker 容器中的 .NET 控制台应用程序,该容器运行良好。

However, this is not so simple when I try to pass command line arguments via the launch.json / task.json files to the application.但是,当我尝试通过 launch.json / task.json 文件将命令行 arguments 传递给应用程序时,这并不是那么简单。 I would have thought this would be fairly common / simple but I have struggled to find anything at all, and my trial and error has got me nowhere.我原以为这会很常见/很简单,但我一直在努力寻找任何东西,而且我的反复试验让我无处可去。 The remaining setup is pretty standard.其余设置非常标准。

How would I pass command line arguments using launch.json and tasks.json?如何使用 launch.json 和 tasks.json 传递命令行 arguments? I have included my setup below.我在下面包含了我的设置。

launch.json:发射.json:

    "configurations": [
    {
        "name": "Docker .NET Core Launch",
        "type": "docker",
        "request": "launch",
        "preLaunchTask": "docker-run: debug",
        "netCore": {
            "appProject": "${workspaceFolder}/MyProject/MyProject.csproj",
        },
    },

tasks.json任务.json

    {
        "type": "docker-build",
        "label": "docker-build: debug",
        "dependsOn": [
            "build"
        ],
        "dockerBuild": {
            "tag": "myproject:dev",
            "target": "base",
            "dockerfile": "${workspaceFolder}/MyProject/Dockerfile",
            "context": "${workspaceFolder}",
            "pull": true
        },
        "netCore": {
            "appProject": "${workspaceFolder}/MyProject/MyProject.csproj"
        }
    },
    {
        "type": "docker-run",
        "label": "docker-run: debug",
        "dependsOn": [
            "docker-build: debug"
        ],
        "dockerRun": {
        },
        "netCore": {
            "appProject": "${workspaceFolder}/MyProject/MyProject.csproj",
            "enableDebugging": true
        }
    },

You can skip these configs and utilize command arguments in the docker entry point, it'll be more easier.您可以跳过这些配置并在 docker 入口点中使用命令 arguments ,它会更容易。

Set up a new scripts file, entry.sh设置一个新的脚本文件 entry.sh

#!/bin/bash
echo Arguments - "$@"

Prepare your dockerfile like this像这样准备您的 dockerfile

FROM ubuntu:22.04
COPY ./entry.sh /
chmod +x entry.sh
ENTRYPOINT ["/entry.sh"]

Build and run your docker image构建并运行您的 docker 映像

docker run mycontainer HelloWorld

And you'll see your arguments there !你会在那里看到你的 arguments !

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过 docker 运行将命令行 Arguments 传递到 .NET 控制台应用程序(Docker for Windows) - How to pass Command Line Arguments to .NET Console App through docker run (Docker for Windows) .NET控制台应用程序命令行解析文件参数 - .NET Console app command line parsing of file arguments 添加应用程序参数以在Docker中运行.NET控制台应用程序 - Add application arguments to run .NET console app in Docker 控制台应用程序的命令行参数在一台计算机上而不是另一台计算机上被截断 - Command line arguments for console app are getting truncated on one machine and not another 如何从命令行提供.net控制台应用程序? - How to make a .net console app available from the command line? 如何将宏用于命令行参数以调试.NET项目? - How do I use macros for the command line arguments for debugging a .NET project? 使用命令行参数自定义容器配置 - Customize container configuration with command line arguments 在Docker容器中运行标准.NET控制台应用程序 - Running a standard .NET Console Application in docker container 在控制台应用程序中,防止转义命令行参数中特殊序列的最佳方法是什么? - in a console app what's the best way to prevent special sequences in command line arguments from being escaped? 在 Visual Studio 中调试接受命令行 arguments 的 Windows Forms 应用程序 - Debugging Windows Forms application that accepts command line arguments in Visual Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM