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 Shutdown dotnet run
  • F2 Rename with code refactoring

References

User and Workspace Settings

.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
  1. Open the file in the Properties folder of the project.
  2. Under the profiles section change "launchBrowser": true to "launchBrowser": false for either http or https depending on the profile being used.
Release configuration build in VS Code
  1. In the command pallet select .NET: Generate Assets for Build and Debug to generate a .vscode\tasks.json file.
  2. Open the file and copy the generated task with a label of dotnet build release.
  3. Add "--configuration=Release" to the args section.
  4. To execute a release build use the command palette "Tasks: Run Task" / "dotnet build release".
Define .runsettings for unit test execution
  1. 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
  2. Clear all existing test results and restart VS Code.
  3. 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)"


⚠️ **GitHub.com Fallback** ⚠️