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.
Some of the extensions I use:
C# - This is THE C# extension for Visual Studio Code powered by OmniSharp.
.NET Core Test Explorer - An important extension to have live testing while coding in VScode.
Auto-using - Automatically adds the dependencies with using in the head of the current file.
C# FixFormat - It helps to automatically format the code. With the right settings, the code is also formatted when saving the file.
Coverage Gutters - Show the code coverage visualized with color in the editor.
.NET Core Extension Pack - Bundle of helpful extensions.
.NET Core Snippet Pack - A pack of around 120 snippets for .NET Core.
Fakesharper - Integrates Resharper into VSCode
EditorConfig - Overwrites the VScode settings with the settings provided in the .editorconfig file.
The extensions were one part of the solution.
The other part was the settings. I provide the settings for VSCode with every project to install the recommended modules, activate the Roslyn Analyzer feedback ( which provides the StyleCop information,… ), activate the TestExplorer to use the Live Testing feature and activate the automatic format of the code.
The important settings in my .vscode/settings.json in the project are typically the following:
1"dotnet-test-explorer.testProjectPath": "**/*Test.csproj",2 "dotnet-test-explorer.autoWatch": true,3 "dotnet-test-explorer.testArguments": "/p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput=./lcov.info",4 "cSpell.words": [5 "Xunit"6 ],7 "omnisharp.enableRoslynAnalyzers": true,8 "csharpfixformat.sort.usings.enabled": true,9 "csharpfixformat.sort.usings.systemFirst": false,10 "csharpfixformat.style.braces.onSameLine": false,11 "csharpfixformat.style.spaces.beforeParenthesis": false,12 "csharpfixformat.style.spaces.afterParenthesis": false,13 "editor.formatOnSave": true,14 "[csharp]": {15 "editor.defaultFormatter": "Leopotam.csharpfixformat"16 }
If you add StyleCop.Analyzers via NuGet to your projects the “omnisharp.enableRoslynAnalyzers”: true - setting will provide this information in the editor.
To adjust the StyleCop ruleset and use the Ruleset in the root folder append the path to the ruleset in the csproj of all projects.
1<PropertyGroup>2 <CodeAnalysisRuleSet>..\StyleCop.ruleset</CodeAnalysisRuleSet>3</PropertyGroup>
To get the coverage statistics working it’s also needed to add the coverlet.msbuild package to the Test project.
A complete example template is available under github.com/dominicboettger