MSDN Documentation

Microsoft Developer Network

Deploying .NET Core Applications

This document provides a comprehensive guide to deploying your .NET Core applications across various environments. Understanding deployment strategies is crucial for making your applications accessible to users and ensuring they run reliably.

Deployment Fundamentals

.NET Core applications can be deployed in two main ways:

Deployment Scenarios

Choose the deployment scenario that best fits your needs:

1. Deploying to Windows

For Windows deployments, you can utilize:

Example command for self-contained deployment to Windows (x64):

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

2. Deploying to Linux

Linux deployments are common for server-side applications and microservices.

Example command for self-contained deployment to Linux (Ubuntu x64):

dotnet publish -c Release -r ubuntu.20.04-x64 --self-contained true

3. Deploying to macOS

macOS deployments can also leverage self-contained executables.

Example command for self-contained deployment to macOS (x64):

dotnet publish -c Release -r osx-x64 --self-contained true

4. Containerization with Docker

Docker provides an efficient way to package and deploy .NET Core applications. You can use official .NET Core Docker images as base images.

Tip: Using multi-stage builds in your Dockerfile can significantly reduce the final image size by separating build dependencies from runtime.

A basic Dockerfile might look like this:

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /app
COPY *.csproj ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build /app/out .
ENTRYPOINT ["dotnet", "YourApp.dll"]

Deployment Best Practices

Note: For framework-dependent deployments, ensure the target machine has a compatible .NET Core runtime version installed. You can check installed runtimes using the dotnet --list-runtimes command.

Further Reading