net-core
  1. net-core-publish-and-deploy

Publish and Deploy - ASP.NET Core Deployment & Hosting

When you have finished creating your ASP.NET Core web application, it's time to publish and deploy it to your hosting environment. There are different ways of doing it, and in this page, we will discuss the most common methods for publishing and deploying your ASP.NET Core app.

Hosting Options

Before we publish and deploy our application, we need to decide where it will be hosted. Here are the most common hosting options for ASP.NET Core web applications:

  • Self-hosting: Running the application on a locally hosted web server on your computer or network.
  • Cloud hosting: Hosting the application in a cloud-based environment such as Azure, AWS, or Google Cloud.
  • Shared hosting: Hosting the application in a shared server environment typically used by smaller websites.

Publish Options

After choosing a hosting option for our ASP.NET Core application, we can then publish the application using one of the following methods:

1. Folder Publish

Folder publish creates a set of files representing a fully static, standalone version of the application which can be copied to any web server. It allows you to compile your application and create a set of files that can be deployed to your web server using FTP or any copying tool. This mode of publishing is ideal for self-hosting and shared hosting environments.

2. Web Deploy

Web Deploy is a Microsoft tool that automates the deployment of web applications from a development environment to a hosting environment. It allows you to publish your application directly to IIS, Azure Web Apps and other servers, and also supports publishing only the changes between your local application and the remote server, which makes for faster deployments.

How to Publish and Deploy

Here are the general steps to follow to publish and deploy an ASP.NET Core application:

1. Configure the Build

Before we publish the application, we need to configure it to optimize for deployment. To do so, we can add the following section to the project file (*.csproj):

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
    <MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
    <PublishReadyToRun>true</PublishReadyToRun>
    <DebugType>none</DebugType>
    <DebugSymbols>false</DebugSymbols>
    <Optimize>true</Optimize>
    <LangVersion>9.0</LangVersion>
  </PropertyGroup>

2. Publish the Application

In Visual Studio, right-click on the project in the Solution Explorer, and select "Publish". You can then select the desired publishing option, such as "Folder Publish" or "Web Deploy", and follow the steps to complete the publishing process.

3. Deploy the Application

After the application has been published, we can deploy it to our hosting environment using FTP or any other tool necessary for the hosting environment we have selected.

Important Points

  • There are different hosting options to consider for ASP.NET Core applications, including self-hosting, cloud hosting, and shared hosting.
  • The two most common publish methods for ASP.NET Core applications are "Folder Publish" and "Web Deploy".
  • Before publishing and deploying our application, we need to optimize it for deployment by configuring the build.

Summary

In this page, we discussed the most common methods for publishing and deploying your ASP.NET Core app. We covered hosting options, publish options, and the general steps to follow for publishing and deploying your application. By understanding these steps and options, you can choose the best approach for your specific deployment needs.

Published on: