在Visual Studio代码中发布版本

时间:2017-12-17 12:09:57

标签: c# visual-studio-code

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

现在我使用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"
        }
    ]
}

4 个答案:

答案 0 :(得分:8)

像这样编辑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

答案 1 :(得分:1)

您可以在没有task.json的情况下进行操作,而只需使用Launch.json

这是我经常用来通过F5构建C#项目的配置: Gist

答案 2 :(得分:0)

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

答案 3 :(得分:0)

您可以使用以下命令通过终端执行发布构建:

dotnet build -c release

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

dotnet run -c release

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