Publishing and deploying your app
An app is only useful once it runs somewhere users can reach. This lesson explains dotnet publish, framework-dependent and self-contained output, the common hosting options, and a checklist for a safe first deployment.
- StartPublishdotnet publish -c Release produces optimized output
- Step 2PackageA folder, a zip, or a container image
- Step 3Configure the serverASPNETCORE_ENVIRONMENT, connection strings and secrets as environment variables
- Step 4Update the databaseRun the migration script or bundle
- Step 5Start the appBehind IIS, Nginx, a container platform or Azure App Service
- EndCheck and monitorOpen the site, watch logs and health checks
The idea in plain words
dotnet publish compiles your app in Release mode and gathers everything needed to run it into one folder. A framework-dependent publish is small but needs the matching .NET runtime on the server. A self-contained publish includes the runtime, so the server needs nothing installed, at the cost of a bigger output.
In production the Kestrel server usually sits behind something else: IIS on Windows (with the ASP.NET Core Hosting Bundle installed), Nginx or Apache on Linux as a reverse proxy, a container platform, or a managed service such as Azure App Service, which handles the server for you.
Example: publish commands
# Framework-dependent (server needs the .NET runtime)
dotnet publish -c Release -o ./publish
# Self-contained for Linux x64
dotnet publish -c Release -r linux-x64 --self-contained true -o ./publish-linux
# Build a container image directly with the .NET SDK
dotnet publish -c Release /t:PublishContainer
# Run on the server
cd publish
ASPNETCORE_ENVIRONMENT=Production dotnet MyShop.dllFirst deployment checklist
- Environment is Production, and detailed errors are off.
- Secrets come from environment variables or a vault, not appsettings.json in source control.
- HTTPS is configured, with HSTS and forwarded headers behind a proxy.
- Database migrations have been applied with a script or bundle.
- Logs go somewhere you can read them, and a health check URL responds.
- You know how to roll back to the previous version.
In Visual Studio 2026
Right-click the project and choose Publish. The wizard offers targets such as Azure App Service, Docker Container Registry, a folder, IIS or FTP. For a first try pick Folder, accept the default path and click Publish; Visual Studio runs dotnet publish in Release mode and opens the output folder. The publish profile is saved, so next time it is one click.
Common mistakes
- Publishing in Debug configuration.
- Copying the whole project folder, including source code and secrets, to the server instead of the publish output.
- Running Kestrel directly on the internet without a plan for TLS certificates and process restarts.
- Deploying without a way to see logs.
Interview question
What is the difference between a framework-dependent and a self-contained deployment?
A framework-dependent deployment contains only your app and its dependencies and relies on a shared .NET runtime installed on the machine, so it is small and benefits from runtime security updates installed on the server. A self-contained deployment bundles the .NET runtime for a specific platform (runtime identifier), so it runs without a runtime installed and is isolated from other apps, but is larger and must be republished to get runtime patches.
Want the full details? Read the official Microsoft documentation for this topic.