Here are the main steps you perform to deploy an ASP.NET Core app to a hosting environment:
- Publish the app to a folder on the hosting server.
- Set up a process manager that starts the app when requests come in and restarts it after it crashes or the server reboots.
- Set up a reverse proxy that forwards requests to the app.
Publish to a folder
The dotnet publish CLI command compiles application code and copies the files needed to run the application into a publish folder. When you deploy from Visual Studio the
dotnet publish step is done for you automatically before files are copied to the deployment destination.
The publish folder contains .exe and .dll files for the application, its dependencies, and optionally the .NET runtime.
A .NET Core app can be published as self-contained or framework-dependent. If the app is self-contained, the .dll files that contain the .NET runtime are included in the publish folder. If the app is framework-dependent, the .NET runtime files are not included because the app has a reference to a version of .NET that is installed on the computer. The default deployment model is framework-dependent. For more information, see .NET Core application deployment.
In addition to .exe and .dll files, the publish folder for an ASP.NET Core app typically contains configuration files, static assets, and MVC views. For more information, see Directory structure.
Set up a process manager
An ASP.NET Core app is a console app that has to be started when a server boots and restarted after crashes. To automate starts and restarts you need a process manager. The most common process managers for ASP.NET Core are Nginx and Apache on Linux, and IIS and Windows Service on Windows.
Set up a reverse proxy
If your app uses the Kestrel web server and will be exposed to the Internet, you must use Nginx, Apache, or IIS as a reverse proxy server. A reverse proxy server receives HTTP requests from the Internet and forwards them to Kestrel after some preliminary handling. The main reason for using a reverse proxy is security. For more information, see When to use Kestrel with a reverse proxy.
Using Visual Studio and MSBuild to automate deployment
Deployment often requires additional tasks besides copying the output from
dotnet publish to a server. For example, you might want to include extra files in the publish folder, or exclude files from it. Visual Studio uses MSBuild for web deployment, and you can customize MSBuild to do many other tasks during deployment. For more information, see Publish profiles in Visual Studio and the Using MSBuild and Team Foundation Build book.
You can deploy directly from Visual Studio to Azure App Service by using the Publish Web feature or by using built-in Git support. Visual Studio Team Services supports continuous deployment to Azure App Service.
For information about using Docker as a hosting environment, see Host ASP.NET Core apps in Docker.