在构建我的C#项目时,如何在VS Code中切换到Release配置?
现在我使用Ctrl+F5
或Debug -> 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"
}
]
}
答案 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 Release
和Build 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