Wednesday, January 13, 2021

Visual Studio Code: More Efficient Building of a WebService Project

A .NET 5 WebApi project was create in post Visual Studio Code: Creating a C#/WebApi Project with .Net 5. Building a Visual Studio Code project such as the previous example is actually a bit tedious and it does not have to be. This post will show how building a .NET 5 Web Api project in Visual Studio Code behaves by default and how it can be made more efficient.

To build the project we previously created, select Terminal | Run Build Task (a.k.a. CTRL-SHIFT-B):


When Terminal | Run Build Task the Command Palette is displayed with the build command provided in the dropdown:


Running build from the Command Palette builds the project. It would make more sense if invoking Terminal | Run Build Task simply builds the project. To achieve this, open the .VSCode folder's tasks.json file:


Under line 14 shown above the following text needs to be added as it identifies the default build task;

"group": {
        "kind": "build",
        "isDefault": true
      }

The updated launch.json file looks as follows with the new text added as lines 15 to 18:


Following the addition of the default build task, invoking Terminal | Run Build Task directly builds the project without the middle step of using the Command Palette. CTRL-SHIFT-B will also directly invoke the build.


No comments :

Post a Comment