Development Environment and the .NET CLI

Download the .NET SDK for your operating system from Microsoft (dot.net).

Concept

Download the .NET SDK for your operating system from Microsoft (dot.net). The SDK includes the runtime, so one install is enough for development. On Windows you can also use winget install Microsoft.DotNet.SDK.10; on Linux use your distribution's package manager or Microsoft's install script; on macOS use the installer or Homebrew.

SDK vs runtime: developers install the SDK; production servers typically need only the runtime (or nothing, for self-contained apps).

Multiple SDKs can be installed side by side; dotnet --list-sdks shows them. By default the newest SDK is used.

global.json pins the SDK version for a folder tree, which keeps team builds reproducible:

IDEs and Editors Visual Studio (Windows) Full IDE: designer tools, debugger, profiler, test explorer Visual Studio Code + C# Dev Kit

Lightweight, cross-platform, excellent debugging Cross-platform IDE with strong refactoring

dotnet CLI plus any editor; how CI servers build code dotnet new <template>

Create a project (console, classlib, webapi, xunit, …) dotnet build

Compile the project and its dependencies Build and run (also dotnet run file.cs for single-file apps in.NET 10) Run unit tests dotnet clean Delete build outputs dotnet restore

Download NuGet dependencies (runs automatically during build) dotnet publish

Produce deployable output (framework-dependent, self-contained or Native AOT) Create a NuGet package

dotnet add package <id> / remove package / list package Manage NuGet references Manage solution files

A console project created by dotnet new console -n HelloApp contains:

The .csproj for a console app:

Solution files (.sln / .slnx) group several projects.

Project references (<ProjectReference Include="..\Lib\Lib.csproj" />) link your own projects; package references (<PackageReference Include="..." Version="..." />) link NuGet packages.

Build configurations: Debug (no optimizations, full debugging) and Release (optimized): dotnet build -c Release.

bin holds final outputs; obj holds intermediate files. Neither belongs in source control.

{
  "sdk": {
    "version": "10.0.401",
    "rollForward": "latestFeature"
  }
}
HelloApp/
├── HelloApp.csproj      ← project file (MSBuild XML)
├── Program.cs           ← source code
├── bin/Debug/net10.0/   ← build output (HelloApp.dll, HelloApp.exe apphost)
└── obj/                 ← intermediate files, restore data
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
</Project>

Why It Matters

Every C# developer and every CI pipeline uses the SDK and CLI. Understanding projects, configurations and output folders is needed to build, debug, package and deploy anything.

Syntax

dotnet new console -n MyApp        # create
cd MyApp
dotnet build -c Release            # compile
dotnet run -- arg1 arg2            # run with arguments (after --)
dotnet publish -c Release -r win-x64 --self-contained

Example

A real session creating, building and running a new console application:

dotnet --version
dotnet new console -n HelloApp
cd HelloApp
dotnet build -v q -nologo
dotnet run

Expected Result

(The folder path, restore and build times will differ on your machine.)

> dotnet --version
10.0.401
> dotnet new console -n HelloApp
The template "Console App" was created successfully.

Processing post-creation actions...
Restoring C:\demo\HelloApp\HelloApp.csproj:
  Determining projects to restore...
  Restored C:\demo\HelloApp\HelloApp.csproj (in 96 ms).
Restore succeeded.
> cd HelloApp
> dotnet build -v q -nologo

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.61
> dotnet run
Hello, World!

Common Mistakes

Running dotnet run in a folder that has no project file ("Couldn't find a project to run").

Committing bin/ and obj/ to Git — add them to .gitignore (dotnet new gitignore creates one).

Forgetting -- before program arguments: dotnet run -- --verbose passes --verbose to your program, not to the CLI.

Deploying Debug builds to production.

Mismatched SDKs between developers — use global.json.

Best Practices

Enable <Nullable>enable</Nullable> and <ImplicitUsings>enable</ImplicitUsings> (the defaults in new templates).

Use <TreatWarningsAsErrors>true</TreatWarningsAsErrors> in CI for new code.

Keep one solution per product, with separate projects for app, libraries and tests.

Learn the CLI even if you use an IDE — CI servers only have the CLI.

Interview Relevance

Medium: "What is in a .csproj?", "SDK vs runtime?", "Debug vs Release?", "framework-dependent vs self-contained deployment?".

Practice Questions

Create a console app, change the message, and run it.

Build it in Release mode and find the output .dll.

Create a class library with dotnet new classlib and reference it from the console app with dotnet add reference.

What does global.json do?

Publish the console app as a self-contained executable for your OS.

Quick Quiz

Q1. (Multiple choice) Which command compiles and immediately runs a project? A) dotnet build B) dotnet run C) dotnet publish D) dotnet new Answer: B.

Q2. (True/False) Production servers must always have the full .NET SDK installed.

Answer: False. They need at most the runtime; self-contained or Native AOT apps need neither.

Q3. (Find the bug) dotnet run --verbose does not pass --verbose to the program. Why?

Answer: Arguments for the program must come after --: dotnet run -- --verbose.

Q4. (Multiple choice) Which folder contains the compiled .dll? A) obj/ B) bin/<Configuration>/<TargetFramework>/ C) src/ D) packages/

Coding Challenge

Write the commands to create a solution Garage.sln containing a console app Garage.App and a class library Garage.Core, where the app references the library.

dotnet new sln -n Garage
dotnet new classlib -n Garage.Core
dotnet new console -n Garage.App
dotnet sln Garage.sln add Garage.Core/Garage.Core.csproj Garage.App/Garage.App.csproj
dotnet add Garage.App/Garage.App.csproj reference Garage.Core/Garage.Core.csproj
dotnet build