sashoalm
sashoalm

Reputation: 79685

Release build in VS Code

When building my C# project, how can I switch to Release configuration in VS Code?

Right now I launch my application with Ctrl+F5 or Debug -> Start Without Debugging which also builds it, but this creates only a debug build at bin/Debug. There is no Build menu in VS Code.

Here's my tasks.json:

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

Upvotes: 35

Views: 45338

Answers (5)

Mladen
Mladen

Reputation: 31

If you are using C#DevKit extension for .NET than:

  1. Ctrl+Shift+P or View -> Command Palette... opens "Command Palette"
  2. Search for ".NET: Select a Configuration..."
  3. Choose Release.

Build with Ctrl+Shift+B. If there's no bulid task, you will be prompted to choose one.

Run in "Terminal" window with dotnet run -c Release.

Upvotes: 2

V Bota
V Bota

Reputation: 617

Edit the tasks.json like this:

{
    "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"
        }        
    ]
}

then when you press Ctrl+Shift+B the Command Palette will let you choose between Build Release and Build Debug

source: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-build?tabs=netcore2x

Upvotes: 42

You can perform a release build via the terminal with:

dotnet build -c release

If you want to run in release, use:

dotnet run -c release

Source: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-build

Upvotes: 18

John Jang
John Jang

Reputation: 2985

Terminal -> Run Task... -> select the task name to run

Upvotes: 1

Parsa
Parsa

Reputation: 11764

you can just do that without tasks.json , but with Launch.json

Here is a configuration I always use to build my C# projects by F5 : Gist

Upvotes: 3

Related Questions