How to publish ASP.NET Core web application via Visual Studio 2019

Authoring Tools > Visual Studio 2019
This article contains the most detailed steps for publishing ASP.NET Core web application to our web server using Visual Studio 2019.

1. Initial Setup at Dreamnix.com

Create a website and a SQL Server database from your hosting Control Panel. For more details, please check the below links
  1. Create a website
  2. Create a database
In the section following we will review some of the detail of the setup in order to get the values to need to publish the project

2. Creating the Project in Visual Studio

Build the project using the Visual Studio templates:
 
 
vs2019_wd_01
 
vs2019_wd_02
 
Since all your sites are using the same application pool in the hosting plan, please use OutOfPorcess hosting model for all your ASP.NET Core applications.
 
You can easily configure the setting in local VS, this will publish the application as OutOfProcess hostingModel automatically.
 
vs2019_wd_03
 
 
Please note, in this example, Individual User Accounts is selected for Authentication.  This means that the default build will include a database context “ApplicationDbContext” and a migration for creating the Identity Schema. Once the project is created and the command "Update-Database" is run in the VS Package Manager Console, a local database instance is created with a set of tables associated with the user identity.  These can be seen by viewing the "localdb" in the VS SQL Server Object Explorer.
It is not a requirement to use individual user accounts, however, if the project does not, it will be necessary to create a database context, add one or more data object, and run the "Add-Migration Initial" and "Update-Database" commands in the VS Package Manager Console in order to demonstrate the steps involving the database.
 
vs2019_wd_04
 
3. Preparing to Publish the Project
There are several critical, and somewhat cryptic, values that need to be entered into the VS Publish dialogs and it is useful to collect these in advance.
 
For more details on how to find Web Deployment Information 
 
The database connection string can be found by selecting the “Databases” icon from your Control Panel, and then the “Connection String Examples”.  Use the option titled “ASP.NET”.
Note that this string includes the user name and password credential for the database (not to be confused with those of the site.)  Your user name will be shown correctly but you will need to fill in your password.
Database Connection String:  The database connection that will be used after the site is published.  Note that this value is not stored in the project file “appsettings.json”, which stores the “Default Connection” to the local database.
For more details on how to find your database connection string
 

4. Publish the Project

Right-click on the project name in the VS Solution Explorer and select Publish from the context menu.
 
vs2019_wd_05
 
vs2019_wd_06
 
vs2019_wd_07
 
vs2019_wd_08
 
vs2019_wd_09
 
Enter the real password and check "Save password", click "Validate connection"  button, in the upcoming window, click "Accept".
 
vs2019_wd_10
 
vs2019_wd_11
 

Press the Next button to get to the second screen.
 
On the second screen, accept default values:
    Configuration: Release
    Target Framework: net5.0
    Deployment Mode: Framework-Dependent Note: you can choose 'Self-Contained' if the core version is not installed on the server.
    Target Runtime: Portable
Expand the lists on the second screen and check all of the boxes on both screens.  Note that VS may fill in the database field(s) with the local connection. This is incorrect; both the Databases and the Entity Framework Migrations text fields should contain the path to the database on the server, as you got from step #3.
 
 
vs2019_wd_12
 
If you get the error "ERROR_CERTIFICATE_VALIDATION_FAILED", please re-validate the connection in the previous captured "Publish Connection" window, or add the following line in .pubxml file.
<AllowUntrustedCertificate>true</AllowUntrustedCertificate>
If you want to set value of ASPNETCORE_ENVIRONMENT while deploying, please add the following line in .pubxml file.
<EnvironmentName>Production</EnvironmentName>
 
vs2019_wd_13
 
 
Once you have created a profile you can reuse it every time that you publish by simply running the Publish command.
Observer the Output window in VS to see if the publication worked properly.
 
vs2019_wd_14