.csproj FormatModern .NET uses a simplified, SDK-style .csproj format that is much cleaner than the legacy format. It is XML-based but requires far fewer lines.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
</Project>
The Sdk attribute tells MSBuild which set of build targets and tasks to import. Common SDKs are Microsoft.NET.Sdk (console, classlib, test) and Microsoft.NET.Sdk.Web (ASP.NET Core).
MSBuild is the build engine underlying all .NET builds. It processes XML-based project files and executes targets (build steps) composed of tasks (individual operations).
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="OldCode\**" />
<EmbeddedResource Include="Resources\**\*" />
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<Target Name="CustomStep" AfterTargets="Build">
<Message Text="Build completed!" Importance="high" />
<Copy SourceFiles="output.dll" DestinationFolder="..\deploy\" />
</Target>
Metapackages reference a group of related NuGet packages without adding any code of their own:
Microsoft.NET.Sdk.Web SDK which automatically references Microsoft.AspNetCore.App. You do not need to add it as a PackageReference.
dotnet restore # Downloads missing packages and resolves dependencies
dotnet build # Compiles the project incrementally
dotnet build --no-restore # Skips restore for faster incremental builds
dotnet restore is implicit in dotnet build, dotnet run, and dotnet test unless you pass --no-restore.
| Property | Description |
|---|---|
TargetFramework | Target framework moniker (e.g., net8.0, netstandard2.0) |
OutputType | Exe, Library, WinExe, Module |
LangVersion | C# language version (e.g., 12, latest) |
Nullable | Enable nullable reference types (enable/disable/annotations/warnings) |
ImplicitUsings | Auto-import common namespaces (enable/disable) |
PublishAot | Enable NativeAOT compilation (true/false) |
.csproj. Add a custom MSBuild target that copies the output DLL to a deploy folder after each build. Verify it runs with dotnet build.