Skip to main content

Deployment and Publishing

Level: Intermediate to Advanced

ℹ️ What You'll Learn
  • Publishing vs building
  • Framework-dependent deployment
  • Self-contained deployment
  • Deployment on different platforms
  • Docker containerization basics
  • Azure App Service deployment

Publish vs Build

Build: Compile to MSIL, stored locally in bin/

Publish: Create deployment package, ready for production

Framework-Dependent Deployment (FDD)

Requires .NET installed on target server.

dotnet publish -c Release

Creates folder: bin/Release/net8.0/publish/

Contains:

  • Your .dll files
  • Dependencies
  • Configuration files

Target server needs: .NET 8 Runtime

Advantages: Smaller package (no runtime)

Use for: Azure App Service, shared servers

Self-Contained Deployment (SCD)

Includes .NET runtime with app.

dotnet publish -c Release -r win-x64 --self-contained

-r flag: Runtime identifier

  • win-x64 — Windows 64-bit
  • linux-x64 — Linux 64-bit
  • osx-x64 — Mac Intel
  • osx-arm64 — Mac Apple Silicon

Target server needs: Nothing (includes .NET)

Advantages: Works anywhere, no .NET dependency

Disadvantages: Larger package (includes runtime)

Publish a Project

dotnet publish -c Release

Creates publish/ folder with everything needed.

Copy publish/ folder to server, run.

Docker Deployment

Package app in Docker container.

Dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /build
COPY . .
RUN dotnet publish -c Release -o output

FROM mcr.microsoft.com/dotnet/runtime:8.0
WORKDIR /app
COPY --from=build /build/output .
ENTRYPOINT ["dotnet", "SchoolAPI.dll"]

Build and run:

docker build -t schoolapi:1.0 .
docker run -p 8080:80 schoolapi:1.0

Azure App Service Deployment

For ASP.NET Core APIs.

  1. Create App Service in Azure Portal
  2. Publish from Visual Studio:
    • Right-click project → Publish
    • Select Azure App Service
    • Create or select existing service
  3. Azure deploys automatically

Linux Server Deployment

  1. Create Release build
  2. Copy to server
dotnet publish -c Release -r linux-x64 --self-contained
  1. On server:
chmod +x SchoolAPI
./SchoolAPI

Publishing Settings

Configure in csproj:

<PropertyGroup>
<PublishTrimmed>true</PublishTrimmed>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishSingleFile>true</PublishSingleFile>
</PropertyGroup>
  • PublishTrimmed: Remove unused code (smaller)
  • PublishReadyToRun: Pre-compile for target platform (faster startup)
  • PublishSingleFile: Single .exe file (convenient)

Versioning for Deployment

Update version in csproj before publish:

<PropertyGroup>
<Version>1.2.0</Version>
</PropertyGroup>

Visible in:

  • File properties
  • Package information
  • Assembly version
🎯 Interview Favourite

Q: What is the difference between framework-dependent and self-contained deployment?

Good Answer: "Framework-dependent deployment (FDD) publishes your application without including the .NET runtime, requiring the server to have .NET installed. Use with dotnet publish -c Release. It creates a smaller package but depends on the server having exactly the right .NET version. Self-contained deployment includes the full .NET runtime, so the application works anywhere without pre-installed .NET. Use dotnet publish -c Release -r win-x64 --self-contained specifying the target runtime. SCD is larger but more portable. For ASP.NET Core on Azure App Service, use FDD. For distributing standalone executables or Docker containers, use SCD."

🤖Use AI to Learn Faster

Use ChatGPT, Claude, or Copilot to go deeper on Deployment and publishing. Try these prompts:

  • "When should I use framework-dependent vs self-contained deployment?"
  • "How do I publish a .NET application for production?"
  • "What is Docker and how does it help with deployment?"
  • "How do I deploy to Azure App Service?"

💡 Tip: After reading this article, paste your own code into AI and ask "What could go wrong here and why?" — fastest way to find edge cases and deepen understanding.

Use these links to continue the full Backend > .NET Platform topic from the top menu:

Target search terms for this lesson: dotnet publish, .net deployment, self contained deployment dotnet, deploy dotnet app.


Next Article

-> Debugging Applications

nexcoding.in