【问题标题】:Release build in Visual Studio Code在 Visual Studio Code 中发布构建
【发布时间】:2017-12-17 12:09:56
【问题描述】:

在构建我的 C# 项目时,如何在 VS Code 中切换到发布配置?

现在我使用Ctrl+F5Debug -> Start Without Debugging 启动我的应用程序,这也构建了它,但这只会在bin/Debug 创建一个调试版本。 VS Code 中没有Build 菜单。

这是我的 tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "build",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/dotnetcore-test.csproj"
            ],
            "problemMatcher": "$msCompile"
        }
    ]
}

【问题讨论】:

    标签: c# visual-studio-code


    【解决方案1】:

    像这样编辑 task.json:

    {
        "version": "2.0.0",
        "tasks": [
            {
                "taskName": "build Debug",
                "command": "dotnet",
                "type": "process",
                "args": [
                    "build",
                    "${workspaceFolder}/dotnetcore-test.csproj"
                ],
                "problemMatcher": "$msCompile"
            },
            {
                "taskName": "build Release",
                "command": "dotnet",
                "type": "process",
                "args": [
                    "build",
                    "${workspaceFolder}/dotnetcore-test.csproj",
                    "-c",
                    "Release"
                ],
                "problemMatcher": "$msCompile"
            }        
        ]
    }
    

    那么当你按下Ctrl+Shift+B 时,Command Palette 会让你在Build ReleaseBuild Debug 之间进行选择

    来源: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-build?tabs=netcore2x

    【讨论】:

    【解决方案2】:

    您可以通过终端执行发布构建:

    dotnet build -c release
    

    如果要在发行版中运行,请使用:

    dotnet run -c release
    

    来源:https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-build

    【讨论】:

      【解决方案3】:

      你可以在没有 tasks.json 的情况下做到这一点,但使用 Launch.json

      这是我在 F5 构建 C# 项目时经常使用的配置: Gist

      【讨论】:

        【解决方案4】:

        终端 -> 运行任务... -> 选择要运行的任务名称

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-04-09
          • 2018-11-16
          • 2016-05-24
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多