.NET SDK Setup, VS Code, CLI & Project Structure Masterclass

โšก C# 12 & .NET 8 ๐ŸŸข Chapter 2 of 35 ๐Ÿ“‚ Phase 1: C# Setup & Tooling ๐Ÿ“… 2026 Edition
๐Ÿ“Œ Covered in this chapter: .NET SDK vs Runtime ยท VS Code Setup ยท C# Dev Kit ยท dotnet CLI ยท dotnet new console ยท dotnet run ยท dotnet build ยท Project Folder Structure ยท .csproj XML Breakdown ยท Common Setup Errors

Welcome to Phase 1 (Chapter 2): .NET SDK Setup, IDEs, .NET CLI & Project Structure Masterclass! To compile and run C# applications, you need the .NET SDK (Software Development Kit). In this lesson, we explore the difference between the SDK and Runtime, setup Visual Studio 2022 and VS Code with C# Dev Kit, master command-line development using the dotnet CLI, dissect .NET project files (.csproj), and resolve common environment setup errors.

1.NET SDK vs .NET Runtime

Before installing tools, it is vital to understand the difference between the .NET SDK and the .NET Runtime:

ComponentWhat it IncludesTarget AudiencePrimary Use Case
.NET RuntimeCLR Execution Engine + Core Class LibrariesEnd users & Production serversExecuting already compiled .NET applications (.dll / .exe)
.NET SDK.NET Runtime + C# Compiler (csc) + MSBuild + dotnet CLI + Project TemplatesSoftware DevelopersCreating, editing, building, debugging, and publishing C# projects
2IDE Options โ€” Visual Studio vs VS Code vs Online Compiler

You can write C# in a variety of environments depending on your Operating System and project scope:

Development Environments Compared:

โ€ข Visual Studio Code (Cross-Platform): Lightweight, fast code editor. Install the official C# Dev Kit extension pack from Microsoft for full Roslyn IntelliSense, project solution explorer, and debugging.

โ€ข Visual Studio 2022 (Windows / macOS): Enterprise-grade IDE featuring GUI layout designers, memory profilers, remote debugging, and database tools.

โ€ข Online C# Compiler: Run C# code snippets instantly in your web browser without installing anything on mana-compiler C# IDE.

3Creating & Running Projects via .NET CLI

The dotnet command-line interface (CLI) is the universal tool for creating, restoring, building, and running .NET projects across Windows, Linux, and macOS.

Terminal Commands โ€” .NET CLI Workflow
# 1. Create a new C# Console application project named HelloCSharp
dotnet new console -n HelloCSharp

# 2. Navigate into the project folder
cd HelloCSharp

# 3. Build and Run the project immediately
dotnet run

# 4. Compile/Build project without executing
dotnet build

# 5. Clean build output directories (bin/ and obj/)
dotnet clean

# 6. Publish optimized production release binaries
dotnet publish -c Release
4Project Folder Structure & .csproj Anatomy

When you create a console application, the .NET CLI generates a clean project layout:

HelloCSharp/ โ”œโ”€โ”€ HelloCSharp.csproj โ† MSBuild XML project configuration file โ”œโ”€โ”€ Program.cs โ† Primary C# source code entry file โ”œโ”€โ”€ bin/ โ† Binary output folder (compiled DLLs & EXEs) โ”‚ โ””โ”€โ”€ Debug/ โ”‚ โ””โ”€โ”€ net8.0/ โ”‚ โ”œโ”€โ”€ HelloCSharp.exe โ”‚ โ””โ”€โ”€ HelloCSharp.pdb (Debug symbols) โ””โ”€โ”€ obj/ โ† Intermediate build state & NuGet assets

The .csproj file contains project metadata and settings written in XML:

XML โ€” HelloCSharp.csproj Configuration
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>
XML ElementExplanation & Function
Sdk="Microsoft.NET.Sdk"Imports standard .NET build rules and Roslyn compilation targets.
<OutputType>Exe</OutputType>Specifies that compilation produces an executable application (vs Class Library .dll).
<TargetFramework>net8.0</TargetFramework>Targets the .NET 8.0 runtime environment.
<ImplicitUsings>enable</ImplicitUsings>Automatically includes standard namespaces like System, System.Linq, System.IO across all files.
<Nullable>enable</Nullable>Enables C# Nullable Reference Types compiler checks to eliminate null reference exceptions.
5Common Setup Errors & Troubleshooting
โš ๏ธ Common Issue 1: 'dotnet' is not recognized as an internal command

This error occurs when the .NET SDK is not installed or its installation directory is missing from your system PATH environment variable. Download the latest SDK installer from dotnet.microsoft.com and restart your terminal session.

โš ๏ธ Common Issue 2: TargetFramework 'net8.0' was not found

This happens if your project targets .NET 8.0, but your machine only has an older SDK installed (e.g., .NET 6 or 7). Run dotnet --version to verify your installed SDK, and update it accordingly.

6Technical FAQs

Q1: How do I view all installed .NET SDKs and runtimes on my computer?

Run dotnet --list-sdks to list SDKs, and dotnet --list-runtimes to list installed runtimes.

Q2: What is NuGet?

NuGet is the official .NET package manager. You can add open-source libraries to your project using dotnet add package PackageName.

Q3: What is a .sln Solution file?

A Solution file (.sln) is a container that groups multiple related .csproj projects (e.g., Web API + Data Access Library + Unit Tests) in a single workspace.