.NET CLI & Project Management

.NET CLI & Project Management in .NET: The .NET Command-Line Interface (CLI) is the foundational toolchain used by developers, automated CI/CD pipelines, and…

The .NET Command-Line Interface (CLI) is the foundational toolchain used by developers, automated CI/CD pipelines, and cloud build environments to create, compile, test, and containerize .NET applications.


1. Project Creation & Template Ecosystem

The CLI provides built-in archetypes for rapid scaffolding:

# 1. Scaffolding Projects
# Console Application
dotnet new console -n DataProcessor -o src/DataProcessor

# ASP.NET Core Minimal Web API
dotnet new webapi -n CatalogService -o src/CatalogService -minimal

# xUnit Testing Project
dotnet new xunit -n CatalogService.Tests -o tests/CatalogService.Tests

# 2. Managing Solution (.sln) Files
dotnet new sln -n ECommercePlatform
dotnet sln add src/DataProcessor/DataProcessor.csproj
dotnet sln add src/CatalogService/CatalogService.csproj
dotnet sln add tests/CatalogService.Tests/CatalogService.Tests.csproj

2. The Development & Build Pipeline

The standard developer workflow is driven entirely through CLI commands:

# Restore package dependencies from configured NuGet feeds
dotnet restore

# Compile code, verify type-safety, and emit binaries
dotnet build --configuration Release

# Run active application with Hot Reload (instant recompilation on save)
dotnet watch --project src/CatalogService run

# Execute automated tests with detailed console reporting
dotnet test --configuration Release --verbosity normal --collect:"XPlat Code Coverage"

# Publish self-contained, trimmed binary for Linux container deployment
dotnet publish src/CatalogService -c Release -r linux-x64 --self-contained -o ./app-dist

3. Dissecting the Modern Project File (.csproj)

Modern .NET project files use clean, SDK-style XML without GUID noise:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <!-- Target runtime framework -->
    <TargetFramework>net8.0</TargetFramework>
    
    <!-- Enforce C# 8+ non-nullable reference types to eliminate NullReferenceException -->
    <Nullable>enable</Nullable>
    
    <!-- Automatically import common namespaces (System, System.Linq, System.Threading.Tasks) -->
    <ImplicitUsings>enable</ImplicitUsings>
    
    <!-- Treat compiler warnings as build-breaking errors in CI -->
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
  </PropertyGroup>

  <ItemGroup>
    <!-- Package References from NuGet -->
    <PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
  </ItemGroup>

  <ItemGroup>
    <!-- Project-to-Project references within the solution -->
    <ProjectReference Include="..SharedKernelSharedKernel.csproj" />
  </ItemGroup>

</Project>

4. Hands-On Practice Challenge

Try executing the following commands in your local terminal:

  1. Create a new console application named MetricsCollector.
  2. Add the popular Humanizer.Core NuGet package using dotnet add package.
  3. Build the project in Release configuration and inspect the bin/Release/net8.0/ directory.