调试时如何在VSCode中使用Asp.Net Core命令行参数?

3

我刚刚阅读了Scott Allen的这篇文章

指定.net core命令行参数的方法似乎很有趣,但是在使用调试器运行时,我们如何从VS Code传递这些参数呢?(通常使用F5命令进行启动,如果设置了launch.json)

例如:dotnet run dropdb migratedb seeddb


1
你尝试过将"args": ["dropdb", "migratedb", "seeddb"]添加到你的launch.json配置中吗? - Matt Bierner
@MattBierner 谢谢,那很简单并且完美地运行。 - Nexus23
很高兴听到这个消息。我已经将评论发布为答案,这样您就可以关闭这个问题了。 - Matt Bierner
1个回答

9
comment复制答案过来
注意:`launch.json` 文件位于项目下的 `.vscode` 文件夹中。
在你的 `launch.json` 中尝试添加:
"args": ["dropdb", "migratedb", "seeddb"]

到目标启动配置

在launch.json中提供上下文

你的launch.json默认会包含一个空的args元素,大致如下:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Launch (web)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "${workspaceFolder}/<YourProjName>/bin/Debug/net6.0/YourProjName.dll",
            "args": [],
            "cwd": "${workspaceFolder}/<YourProjName>",
            "stopAtEntry": false,
            "serverReadyAction": {
            .
            .
            .
            // launch.json file continues...

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接