Deployment and Publishing
Level: Intermediate to Advanced
- 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-bitlinux-x64— Linux 64-bitosx-x64— Mac Intelosx-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.
- Create App Service in Azure Portal
- Publish from Visual Studio:
- Right-click project → Publish
- Select Azure App Service
- Create or select existing service
- Azure deploys automatically
Linux Server Deployment
- Create Release build
- Copy to server
dotnet publish -c Release -r linux-x64 --self-contained
- 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
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 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.
.NET Platform Section Links
Use these links to continue the full Backend > .NET Platform topic from the top menu:
- .NET Platform Fundamentals
- .NET Developer Roadmap
- C# Tutorial
- ASP.NET Core Tutorial
- ASP.NET Core Web API
- SQL Server Tutorial
- .NET Interview Questions
Target search terms for this lesson: dotnet publish, .net deployment, self contained deployment dotnet, deploy dotnet app.