Dominic Böttger

← Back to blog

Optimize Visual Studio Code for C# .NET Core development

Published on May 10, 2020 by Dominic Böttger (5 years ago) · 1 min read

Visual Studio Code is my favorite Code Editor and I like that it’s so lightweight and also wanted to use it for C# development instead of the full-blown Visual Studio experience.

Some time ago I tried to use Visual Studio Code instead but I was missing some things to improve the development workflow. I wanted to have features like live unit testing and better guidance while coding C#. I tested some plugins and some configurations and now I think I found a solution to fulfill my needs.

Essential Extensions

  1. C# - THE C# extension powered by OmniSharp
  2. .NET Core Test Explorer - Live testing while coding
  3. Auto-using - Automatically adds using statements
  4. C# FixFormat - Auto-format code on save
  5. Coverage Gutters - Visualize code coverage
  6. Fakesharper - Integrates Resharper into VSCode

Configuration

Add these settings to .vscode/settings.json:

{
  "dotnet-test-explorer.testProjectPath": "**/*Test.csproj",
  "dotnet-test-explorer.autoWatch": true,
  "dotnet-test-explorer.testArguments": "/p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput=./lcov.info",
  "omnisharp.enableRoslynAnalyzers": true,
  "csharpfixformat.sort.usings.enabled": true,
  "editor.formatOnSave": true,
  "[csharp]": {
    "editor.defaultFormatter": "Leopotam.csharpfixformat"
  }
}

StyleCop Integration

Add StyleCop.Analyzers via NuGet, then add the ruleset path to your csproj:

<PropertyGroup>
  <CodeAnalysisRuleSet>..\StyleCop.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

A complete example template is available at github.com/dominicboettger

Written by Dominic Böttger

← Back to blog

Comments are powered by GitHub Discussions. A GitHub account is required to comment.