All topics
General · Learning hub

Visual Studio notes for developers

Master Visual Studio with a curated set of 4 developer notes — core concepts, patterns, and interview prep. Maintained by the DevRecall team.

Save this stack to your DevRecallMore General notes
Visual Studio

Debugging & Diagnostics

Visual Studio Debugging & Diagnostics Visual Studio has the most powerful .NET debugger available. Conditional breakpoints, Edit and Continue, the Diagnostic To

Visual Studio Debugging & Diagnostics

Visual Studio has the most powerful .NET debugger available. Conditional breakpoints, Edit and Continue, the Diagnostic Tools window, and IntelliTrace collectively cover debugging, profiling, and historical tracing — all from a single IDE.

Breakpoints

# Basic breakpoints
F9              # Toggle breakpoint on current line
F5              # Start debugging
Shift+F5        # Stop debugging
Ctrl+Shift+F5   # Restart debugging
F10             # Step Over (execute line, do not enter method)
F11             # Step Into (enter method)
Shift+F11       # Step Out (finish current method, return to caller)
F5              # Continue (run to next breakpoint)
Ctrl+F10        # Run to Cursor (temporary breakpoint at cursor position)
Shift+F9        # Quick Watch — evaluate expression while debugging

# Advanced breakpoints — right-click breakpoint dot → Conditions
# Condition types:
# "Expression is true": break when orderId == 42
# "When changed":       break when variable value changes
# Hit Count:            break every Nth time (e.g. every 100th iteration)
# Filter:               break only for specific thread/machine/process

# Tracepoint (log message, do not stop execution) — right-click breakpoint → Actions
# Print to Output window: "Processing order {orderId} for user {user.Name}"
# {} inserts current value of expression — no recompile needed

# Breakpoints window — view and manage all breakpoints
# Debug → Windows → Breakpoints (Ctrl+Alt+B)
# Export/Import breakpoint sets (XML file) — useful for sharing debug sessions

# Data breakpoints — break when a memory address changes
# Requires .NET 5+ or Native code
# While paused, right-click variable in Autos/Locals → "Break When Value Changes"

# Function breakpoints — break when a method is entered by name (no source needed)
# Ctrl+Alt+B → New → enter "Namespace.Class.Method"
# Useful for debugging third-party code or IL-generated methods

Debug Windows & Edit and Continue

# Debug windows (Debug → Windows menu while debugging)
# Autos       — variables used in current and preceding statement (auto-selected)
# Locals      — all variables in current scope
# Watch 1-4   — pin any expression to watch its value; evaluates as you step
# Call Stack  — complete call chain; double-click to navigate to frame
# Immediate   — evaluate/execute any C# expression mid-debug
#               e.g. ? user.Email  or  user.Name = "Test Override"
# Output      — Debug.WriteLine() output, event log
# Threads     — all running threads; right-click to freeze/thaw individual threads
# Parallel Watch  — view same variable across all threads simultaneously
# Memory 1-4  — raw memory inspector
# Modules     — loaded assemblies, DLLs, their paths and versions

# Keyboard shortcuts for debug windows
Ctrl+Alt+A   # Immediate Window
Ctrl+Alt+C   # Call Stack
Ctrl+Alt+W,1 # Watch Window 1
Ctrl+Alt+V,A # Autos Window
Ctrl+Alt+V,L # Locals Window

# Edit and Continue — modify code while paused and continue without restart
# Enable: Tools → Options → Debugging → Enable Edit and Continue
# Limitations: cannot add new types, change method signatures, add fields
# Works for: changing method bodies, fixing typos, adjusting logic

# Set Next Statement — skip lines or re-execute code
# Right-click any line while paused → "Set Next Statement" (Ctrl+Shift+F10)
# The yellow arrow (current execution point) jumps to that line
# Useful for re-running a block of code after fixing a condition

Diagnostic Tools & Profiler

# Diagnostic Tools window (opens automatically when debugging in VS 2015+)
# Debug → Windows → Show Diagnostic Tools (Ctrl+Alt+F2)
# Panels:
# Events timeline  — GC collections, snapshots, exceptions, breakpoints as events
# CPU Usage graph  — real-time CPU %; click "Take Snapshot" to capture a call tree
# Memory Usage     — managed heap; click snapshot to diff allocations between snapshots

# CPU profiler — find hot paths without attaching debugger
# Debug → Performance Profiler → CPU Usage → Start
# Let app run, click "Stop Collection"
# Flame chart shows call tree with % inclusive/exclusive time

# Memory snapshot diffing:
# 1. Click snapshot at baseline
# 2. Perform action that may leak
# 3. Click another snapshot
# 4. Compare: click "# Objects" diff — shows types with the most new instances

# Exception Settings (Ctrl+Alt+E)
# Configure which exceptions break execution:
# "Break when thrown" (not just unhandled) — enable for debugging NullReferenceException
# Check: Common Language Runtime Exceptions → System.NullReferenceException
# Add specific exception types using the + button

# IntelliTrace (Enterprise edition only) — record and replay execution history
# Enable: Debug → Options → IntelliTrace → Enable IntelliTrace
# Records method calls, exceptions, and thread activity during debug session
# After stopping: Debug → IntelliTrace Events window shows timeline
# Double-click any event to restore historical state (inspect variables at any past point)
# "Historical Debugging" — step backward through recorded events

# Remote debugging — attach VS to a process on another machine
# Run msvsmon.exe on target machine (Visual Studio Remote Debugger)
# VS: Debug → Attach to Process → Connection Type = Remote (no authentication)
# Enter target machine hostname → select process → Attach
Visual Studio

NuGet & Project Management

NuGet & Project Management NuGet is the .NET package manager. Modern SDK-style .csproj files are lean and composable. Understanding solution structure, project

NuGet & Project Management

NuGet is the .NET package manager. Modern SDK-style .csproj files are lean and composable. Understanding solution structure, project references, and global tooling like Directory.Build.props is essential for maintainable multi-project .NET solutions.

NuGet Package Manager

# NuGet Package Manager UI
# Right-click project → Manage NuGet Packages
# Or: Tools → NuGet Package Manager → Manage NuGet Packages for Solution

# Tabs:
# Browse:   search nuget.org and private feeds
# Installed: packages currently in the project
# Updates:  packages with newer versions available

# NuGet Package Manager Console (PowerShell-based)
# Tools → NuGet Package Manager → Package Manager Console

# Install a package
Install-Package Newtonsoft.Json
Install-Package Microsoft.EntityFrameworkCore -Version 8.0.0
Install-Package Serilog.AspNetCore -ProjectName MyProject.Api

# Update packages
Update-Package                        # Update all packages in solution
Update-Package Newtonsoft.Json        # Update specific package
Update-Package -Safe                  # Update to highest compatible minor/patch (safe)

# Uninstall
Uninstall-Package Newtonsoft.Json

# Restore packages (usually automatic; force restore)
dotnet restore
# Or in PMC:
Update-Package -Reinstall

# List outdated packages (CLI)
dotnet list package --outdated
dotnet list package --outdated --include-transitive   # Including indirect deps

# Add package via CLI (faster than PMC for simple adds)
dotnet add package Microsoft.AspNetCore.Authentication.JwtBearer
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL --version 8.0.4
dotnet add MyProject.Core package MediatR

# Private NuGet feeds (CI, Azure Artifacts, GitHub Packages)
# Add to nuget.config at solution root:
# <packageSources>
#   <add key="AzureArtifacts" value="https://pkgs.dev.azure.com/org/project/_packaging/feed/nuget/v3/index.json" />
# </packageSources>

SDK-Style .csproj Format

<!-- Modern SDK-style .csproj (Visual Studio 2017+, all .NET Core/.NET 5+) -->
<!-- Much shorter than legacy .csproj — automatically includes all .cs files -->

<!-- MyProject.Api/MyProject.Api.csproj -->
<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <RootNamespace>MyProject.Api</RootNamespace>
    <AssemblyVersion>1.0.0.0</AssemblyVersion>
    <Version>$(AssemblyVersion)</Version>
  </PropertyGroup>

  <ItemGroup>
    <!-- NuGet package references -->
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
    <PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
  </ItemGroup>

  <ItemGroup>
    <!-- Project reference (linked project, not NuGet) -->
    <ProjectReference Include="..MyProject.CoreMyProject.Core.csproj" />
    <ProjectReference Include="..MyProject.InfrastructureMyProject.Infrastructure.csproj" />
  </ItemGroup>
</Project>

<!-- Class library project -->
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <!-- Multi-target: <TargetFrameworks>net8.0;netstandard2.1</TargetFrameworks> -->
    <Nullable>enable</Nullable>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <PackageId>MyCompany.MyProject.Core</PackageId>
    <Description>Core domain logic for MyProject</Description>
  </PropertyGroup>
</Project>

Directory.Build.props & global.json

<!-- Directory.Build.props — placed at solution root, applies to ALL projects -->
<!-- MSBuild auto-discovers it by traversing up from each project directory -->
<Project>
  <PropertyGroup>
    <!-- Common properties for all projects in solution -->
    <LangVersion>latest</LangVersion>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <TreatWarningsAsErrors Condition="'$(Configuration)' == 'Release'">true</TreatWarningsAsErrors>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
    <Authors>MyCompany</Authors>
    <Copyright>Copyright © 2024 MyCompany</Copyright>
  </PropertyGroup>
  <ItemGroup>
    <!-- Add common analyzer to all projects -->
    <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
  </ItemGroup>
</Project>

<!-- Directory.Packages.props — Central Package Management (CPM) -->
<!-- When ManagePackageVersionsCentrally=true, define versions here ONCE -->
<Project>
  <ItemGroup>
    <PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
    <PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4" />
    <PackageVersion Include="Serilog.AspNetCore" Version="8.0.1" />
  </ItemGroup>
</Project>
<!-- Then in .csproj files, omit Version attribute: -->
<!-- <PackageReference Include="Microsoft.EntityFrameworkCore" /> -->

// global.json — pin the .NET SDK version at solution root
{
  "sdk": {
    "version": "8.0.101",
    "rollForward": "latestPatch"   // latestPatch | minor | major | disable
  }
}

// rollForward values:
// disable:      use exact version, fail if not installed
// latestPatch:  use latest patch of specified minor (recommended)
// minor:        use latest minor >= specified
// major:        use any newer SDK
Visual Studio

Testing & Extensions

Testing & Extensions Visual Studio's Test Explorer, Live Unit Testing, and Code Coverage tools provide a first-class testing experience. The extension marketpla

Testing & Extensions

Visual Studio's Test Explorer, Live Unit Testing, and Code Coverage tools provide a first-class testing experience. The extension marketplace adds capabilities from code quality tools to AI assistants.

Test Explorer

# Open Test Explorer
# Test → Test Explorer (Ctrl+E, T)

# Supported test frameworks (via NuGet packages):
# MSTest:   Microsoft.VisualStudio.TestTools.UnitTesting
# xUnit:    xunit + xunit.runner.visualstudio
# NUnit:    NUnit + NUnit3TestAdapter

# Run tests
Ctrl+R, A       # Run All Tests
Ctrl+R, T       # Run test under cursor
Ctrl+R, L       # Rerun last test run (failed tests by default)
Ctrl+R, Ctrl+A  # Debug All Tests
Ctrl+R, Ctrl+T  # Debug test under cursor

# Test filtering — search box in Test Explorer
# Traits:  Trait:"Category:Integration"
# Outcome: Outcome:Failed  |  Outcome:Passed  |  Outcome:NotRun
# Project: Project:MyProject.Tests

# Playlist — save a subset of tests to run repeatedly
# Select tests → right-click → Add to Playlist → New Playlist
# Saved as .playlist file in solution

# Test output — view when a test fails
# Click failed test in Explorer → Output pane shows assertion message + stack trace
# Console.WriteLine() and Debug.WriteLine() appear in test output

# Sample xUnit test class
# using Xunit;
# using Moq;
# public class OrderServiceTests {
#   [Fact]
#   public async Task ProcessOrder_ValidOrder_ReturnsOrderId() {
#     var mockRepo = new Mock<IOrderRepository>();
#     mockRepo.Setup(r => r.SaveAsync(It.IsAny<Order>())).ReturnsAsync("order-123");
#     var svc = new OrderService(mockRepo.Object);
#     var result = await svc.ProcessAsync(new Order { Amount = 100 });
#     Assert.Equal("order-123", result.Id);
#   }
#   [Theory]
#   [InlineData(0)]
#   [InlineData(-1)]
#   public async Task ProcessOrder_InvalidAmount_ThrowsException(decimal amount) {
#     var svc = new OrderService(Mock.Of<IOrderRepository>());
#     await Assert.ThrowsAsync<ArgumentException>(() => svc.ProcessAsync(new Order { Amount = amount }));
#   }
# }

Live Unit Testing & Code Coverage

# Live Unit Testing (Visual Studio Enterprise only)
# Test → Live Unit Testing → Start
# Runs affected tests in background as you type
# Shows inline icons next to each line of code:
#   Green checkmark ✓ — covered by a passing test
#   Red X ✗           — covered by a failing test
#   Blue dash —        — not covered by any test

# Pause LUT during refactoring (prevents constant re-runs)
# Test → Live Unit Testing → Pause

# Configure LUT to exclude generated code / specific projects
# .runsettings file (can be specified in Test → Configure Run Settings):
# <RunSettings>
#   <LiveUnitTesting>
#     <Inclusions>
#       <Include><ModulePath>MyProject.Core</ModulePath></Include>
#     </Inclusions>
#     <Exclusions>
#       <Exclude><ModulePath>.*Generated.*</ModulePath></Exclude>
#     </Exclusions>
#   </LiveUnitTesting>
# </RunSettings>

# Code Coverage (requires VS Enterprise; VS Community/Pro with coverlet)
# VS Enterprise: Test → Analyze Code Coverage for All Tests
# Results shown in Code Coverage Results window
# Highlights covered (blue) and uncovered (orange/red) lines in editor

# coverlet (open source — works with all VS editions)
# dotnet add package coverlet.collector
# dotnet add package ReportGenerator (for HTML report)
dotnet test --collect:"XPlat Code Coverage" --results-directory ./coverage
dotnet tool run reportgenerator -- -reports:"coverage/**/coverage.cobertura.xml" -targetdir:"coverage-report" -reporttypes:Html
# Open coverage-report/index.html in browser

Popular Extensions

# Install extensions: Extensions → Manage Extensions → Online tab
# Or download .vsix from marketplace.visualstudio.com

# Productivity
# ReSharper (JetBrains)       — most popular; refactoring, navigation, code analysis
#                               Adds Alt+Enter (context action), Ctrl+Alt+Shift+T (refactor)
#                               Expensive but transformative; free for students/OSS
# CodeMaid                    — clean up formatting, organize using statements, sort members
# Productivity Power Tools    — (free, Microsoft) PowerCommands, Solution Error Visualizer

# Code Quality & Analysis
# SonarLint                   — real-time code smells, bugs, security vulnerabilities
#                               Integrates with SonarQube/SonarCloud server
# .NET Upgrade Assistant      — automated migration from .NET Framework to .NET 6/7/8

# AI Coding Assistants
# GitHub Copilot              — AI code completion, chat; $10/mo or free for students
#                               Install: Extensions → Manage Extensions → search "GitHub Copilot"
# IntelliCode                 — (free, Microsoft) ML-based completion, starred suggestions

# Version Control
# GitFlow for Visual Studio   — visual branch management for GitFlow workflow
# Git History Visualizer      — improved git log/blame view in VS

# .vsix installation (offline)
# 1. Download .vsix from marketplace
# 2. Double-click the .vsix file → VS Extension Installer opens
# 3. Or: Extensions → Manage Extensions → Installed → Install from VSIX

# Solution templates
# File → New → Project → search template name
# Install additional templates via NuGet: dotnet new install
dotnet new install Ardalis.CleanArchitecture.Template
dotnet new cleanarch -o MyProject

# View installed templates
dotnet new list

Keep your Visual Studio knowledge sharp.

Save this stack to your personal DevRecall — add your own notes, track what you're learning, and share what you know with the community.

Get started — free forever