CLR, Ecosystem & Project Structure
.NET: CLR, Ecosystem & Project Structure .NET is Microsoft's cross-platform, open-source framework for building web, desktop, mobile, cloud, and IoT application…
.NET: CLR, Ecosystem & Project Structure
.NET is Microsoft's cross-platform, open-source framework for building web, desktop, mobile, cloud, and IoT applications. .NET 8 (LTS) and .NET 9 are current. The CLR (Common Language Runtime) provides JIT compilation, garbage collection, and type safety.
.NET Ecosystem Overview
ASP.NET Core: web APIs, MVC, Razor Pages, Blazor — runs on Linux/Mac/Windows
Entity Framework Core: ORM for SQL databases (PostgreSQL, SQL Server, SQLite)
MAUI: cross-platform native UI (iOS, Android, Windows, macOS)
Blazor: C# in the browser (WebAssembly) or server-side rendering
.NET CLI: dotnet new, build, run, test, publish — the primary tool
NuGet: package manager (nuget.org). Packages declared in .csproj.
LTS vs STS: even versions (.NET 8, 10) are LTS (3 years); odd versions (9, 11) are STS (18 months)
Project Structure
# Create new projects
dotnet new webapi -n MyApi --use-controllers # REST API with controllers
dotnet new webapi -n MyApi # Minimal API (no controllers)
dotnet new mvc -n MyMvc # MVC with Razor views
dotnet new classlib -n MyLib # Class library
dotnet new xunit -n MyLib.Tests # xUnit test project
# Solution (groups multiple projects)
dotnet new sln -n MySolution
dotnet sln add src/MyApi/MyApi.csproj
dotnet sln add tests/MyApi.Tests/MyApi.Tests.csproj
# Common commands
dotnet run # run the project
dotnet watch run # run with hot reload
dotnet build # compile
dotnet test # run tests
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL
dotnet publish -c Release -o ./publish<!-- MyApi.csproj — project file -->
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>MyApi</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
</ItemGroup>
</Project>Key .NET Concepts
// Namespaces and using
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
// Records (immutable data classes — C# 9+)
public record User(int Id, string Name, string Email);
// var — type inference
var numbers = new List<int> { 1, 2, 3 };
var user = new User(1, "Alice", "alice@example.com");
// LINQ — integrated query language
var admins = users
.Where(u => u.Role == "admin")
.OrderBy(u => u.Name)
.Select(u => new { u.Id, u.Name })
.ToList();
// Nullable reference types (enabled in modern .NET)
string? nullable = null;
string nonNullable = "hello"; // compiler warns if this could be null
// Pattern matching
object obj = "hello";
if (obj is string s && s.Length > 3)
Console.WriteLine(s.ToUpper());
// Switch expression
string label = score switch {
>= 90 => "A",
>= 80 => "B",
>= 70 => "C",
_ => "F"
};