如何使用 C# 开发套件在 Visual Studio Code 中设置 dotnet Release 配置构建?

问题描述 投票:0回答:1

我已经安装了 Visual Studio Code 和“C# Dev Kit”。看起来没有默认的方式让人们选择发布配置构建。

查看文档包,其中提到了tasks.json。使用“任务配置默认构建任务”命令,它为我设置了以下tasks.josn:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "dotnet",
            "task": "build",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": [],
            "label": "dotnet: build"
        }
    ]
}

但我不知道如何修改它来进行发布配置构建。我尝试将其更改为以下内容:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "dotnet",
            "task": "build",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": [],
            "options": {
                "shell": {
                    "executable": "dotnet",
                    "args": [
                        "build",
                        "${workspaceFolder}/TestVSCode.sln",
                        "-c",
                        "Release"
                    ]
                }
            },
            "label": "dotnet: build"
        }
    ]
}

但是它不起作用,因为当我构建时,我仍然在终端窗口上看到这个:

dotnet build /Users/johnleung/TestVSCode/TestVSCode.sln /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary

“C# Dev Kit”是否基本上修复了它,使其只能使用一个特定命令进行构建?

我什至可以创建自己的任务来执行自己的构建命令吗?

visual-studio-code c#-devkit
1个回答
0
投票

命令 “.NET:生成用于构建和调试的资源” 生成

tasks.json
,如下所示(我已省略
publish
watch
任务):

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/MySolution.sln",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary;ForceNoAlign"
            ],
            "problemMatcher": "$msCompile"
        }
    ]
}

生成的文件可用作自定义

dotnet build
任务的模板。将
--configuration=Release
添加到
args
,如下所示:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "dotnet build debug",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/dotnet/Profilometer.sln",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary;ForceNoAlign"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "dotnet build release",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/dotnet/Profilometer.sln",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary;ForceNoAlign",
                "--configuration=Release"
            ],
            "problemMatcher": "$msCompile"
        }
    ]
}

(这里我添加了单独的发布任务并调整了标签。)

之后,通过命令面板调用发布构建:“Tasks: Run Task”/“dotnet build release”。

似乎这个主题应该包含在 C# Dev Kit 文档中,但我找不到它。

© www.soinside.com 2019 - 2024. All rights reserved.