Visual Studio Code - KevinDHeath/Samples GitHub Wiki
Visual Studio Code is a lightweight but powerful source code editor which runs on your desktop and is available
for Windows, macOS and Linux. It comes with built-in support for JavaScript, TypeScript and Node.js and has a
rich ecosystem of extensions for other languages and run-times (such as C++, C#, Java, Python, PHP, Go, .NET).
See Installed Software for a list of extensions I use.
Shortcuts
-
CRTL+/
Comment/Uncomment -
CTRL+.
Quick fixes -
CTRL+B
Toggle the sidebar visibility -
CTRL+J
Toggle the panel visibility -
CTRL+C
Shutdowndotnet run
-
F2
Rename with code refactoring
References
.NET CLI overview
How to manage .NET tools
VS Code Tutorial For C# Developers (YouTube) Dec 12, 2023
Writing C# in VS Code Is Finally Awesome! (YouTube) Jun 8, 2023
VSCode for the C# Developer (YouTube) Jun 7, 2023
C# Dev Kit
Using .NET in Visual Studio Code
Working with C#
Getting Started with C# in VS Code
Testing with C# Dev Kit
CLI examples
dotnet --list-sdks # List all installed SDK versions
cd [repository folder]
dotnet new list # List all template types
dotnet new [type] --help # Specific options
dotnet new gitignore
dotnet new sln --name Samples
md src
cd src
dotnet new webapi --name WebAPI -controllers
cd ..
dotnet sln add src\WebAPI\WebAPI.csproj
dotnet list package # List referenced packages
code . # Start VS Code
Launch ASP.NET Core API with no browser
-
Properties\launchSetting.json
Reference
- Open the file in the Properties folder of the project.
- Under the profiles section change
"launchBrowser": true
to"launchBrowser": false
for eitherhttp
orhttps
depending on the profile being used.
Release configuration build in VS Code
-
.vscode\tasks.json
Reference
- In the command pallet select
.NET: Generate Assets for Build and Debug
to generate a.vscode\tasks.json
file. - Open the file and copy the generated task with a label of
dotnet build release
. - Add
"--configuration=Release"
to theargs
section. - To execute a release build use the command palette "Tasks: Run Task" / "dotnet build release".
Define .runsettings for unit test execution
-
.vscode\settings.json
Reference
- In VSCode settings, search for
.runsettings
*(Extensions > C# > Debugger > Dotnet > Unit Tests: Run Settings Path).
Enter the path relative to the root folder, e.g.:tests\unittest.runsettings
- Clear all existing test results and restart VS Code.
- The output window for
C# Dev Kit - Test Explorer
should show 'Using custom runsettings file at: ...'
dotnet.unitTests.runSettingsPath": ".\\tests\\unittest.runsettings",
Issues:
Most or all Blazor components show up with warnings
Installing Razor Telemetry Version = 7.0.0-preview.24165.1...
Platform: win32, x86_64
Downloading package 'Razor Language Server Telemetry (Windows / x64)' (9680 KB).................... Done!
Validating download...
Integrity Check succeeded.
Installing package 'Razor Language Server Telemetry (Windows / x64)'
Finished
VSCode shows error for WPF project - "The name 'InitializeComponent' does not exist in the current context (CS0103)"