.NET › .NET CLI, SDK & Project Structure (csproj)

What is the structure and purpose of a .csproj file in a modern SDK-style .NET project?

Intermediate

Answer

A .csproj file is an MSBuild XML project file describing how to build a project: target framework, package references, project references, compiler settings, and output type. Modern SDK-style projects (introduced with .NET Core) are dramatically simpler than legacy .NET Framework .csproj files, using implicit file globbing (no need to list every .cs file) and a concise `<Project Sdk="Microsoft.NET.Sdk">` root element.
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
  </ItemGroup>
</Project>
Real-world example A team migrating a legacy .NET Framework project to .NET 8 replaces a 200-line .csproj with explicit file lists with a 15-line SDK-style version relying on automatic globbing.

Common follow-ups: What does implicit file globbing include and exclude by default?;How do multi-targeting projects specify multiple TargetFrameworks?