Visual Studio Code Setup for ASP.NET Core

Daniel Opitz
Daniel Opitz
07 Jul 2023

Introduction

As a developer, you know that with the right tools and settings, you can significantly increase your productivity and make your coding experience more enjoyable. In this article, we will explore the essential Visual Studio Code extensions that every C# and ASP.NET Core developer should have in their toolkit. These extensions will provide powerful features for debugging and testing with code coverage.

Requirements

First, you need to have VS Code installed on your computer. If you don’t have it installed yet, don’t worry!

It’s a free and lightweight code editor that is good for C# and ASP.NET Core development.

Go to the official Visual Studio Code website, download the installer for your operating system and follow the installation instructions.

ASP.NET is an open-source framework for building modern web applications and APIs with C#. To build .NET apps you also have to install the .NET SDK (Software Development Kit) on your machine.

You can install it by visiting the official .NET website, downloading the installer, and following the installation instructions specific to your operating system.

Once you have installed VSCode and ASP.NET, you can proceed with setting up the extensions.

Extensions

Launch VSCode and click on the “Extensions” icon in the left sidebar.

Essential Extensions

These are the most common extensions I would recommend:

Extensions for Testing

To enable testing your ASP.NET Core applications, I would like to share the following useful extension with you:

Test Explorer UI: Allows you to discover and run your unit tests from within Visual Studio Code.

.NET Core Test Explorer: This extension integrates with the Test Explorer UI extension and provides test discovery and execution capabilities specifically for .NET Core projects.

Test Adapter Converter: Converts from the Test Explorer UI API into native VS Code testing.

As a useful helper, the Test Explorer Status Bar adds some some test statistics into the status bar.

The result should look and work pretty awesome:

Test Explorer UI

Code Coverage

Coverage Gutters: Helps you visualize code coverage in your project by displaying colored gutters in the editor, indicating which lines are covered by tests.

To make Coverage Gutters work, you should configure the “Test Explorer UI” key dotnet-test-explorer.testArguments to /p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput=./lcov.info.

Example: .vscode/settings.json

{
  "dotnet-test-explorer.testProjectPath": "**/*Tests.csproj",
  "dotnet-test-explorer.testArguments": "/p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput=./lcov.info",
  "coverage-gutters.showLineCoverage": true,
  "coverage-gutters.showRulerCoverage": true,
  "coverage-gutters.showGutterCoverage": true,
}

Coverage Gutters in action:

Coverage Gutters

Useful Extensions

Besides the the essential extensions, I would like to recommend other very useful extensions, that will give you a even better developer experience.

Thunder Client is a lightweight REST API client that allows you to make HTTP requests and view responses within VS Code.

Auto-Using for C# automatically adds missing using statements for C# code, saving you time and reducing manual effort.

C# Namespace Autocompletion provides intelligent autocompletion for C# namespaces, making it easier and faster to import the namespaces you need.

Studio Icons: Official icons from the Visual Studio Image Library. Optimized to work well for dark, light, and high contrast themes.

Once you have installed all these extensions, you’ll have a comprehensive development environment for C# and ASP.NET Core in Visual Studio Code. Make sure to enable any necessary settings or configurations for specific extensions, and explore their documentation for more details on how to use their features effectively.

Read more