This article introduces the method of deploying.NET Core to Linux server. Through this article, you will understand the installation of Linux in virtual machine, the use of Xshell,Xftp, the interactive use of Git in Linux and the release and operation of.NET Core in Linux. This article summarizes some experience and notes in the deployment process encountered some problems, and share with you for your reference, welcome to discuss and exchange.

1, Linux operating system, Xshell, Xftp installation

The operating system can be a Linux distribution that you are familiar with. If you are new to Linux, CentOs is recommended, since this article will be demonstrated on CentOs.

For the system installation, you can choose a cloud server, or use a virtual machine installation. For details about how to install CentOs on a VM, see

1.1. Xshell connection tool

We recommend use XShell as a connection tool, download address: www.netsarang.com/zh/xshell-d…

Xshell is a powerful secure terminal simulation software, it supports SSH1, SSH2, and The TELNET protocol of Microsoft Windows platform. Xshell helps users enjoy their work in a complex network environment through secure Internet connections to remote hosts and its innovative design and features.

Xshell can be used in Windows to access servers in different systems on the remote end, so as to better achieve the purpose of remote control terminal. In addition, it has a rich look and feel color scheme and style choices.

After the installation is completed, open the software and click the “New callback” button in the upper left corner to open the “New callback” attribute, as shown below:

Fill in the IP address of the server in “Host”, set the corresponding user and password, and then click “Connect” button. The interface for successful connection is as follows:

1.2. Xftp file upload tool

External interaction with Linux service files can use Xftp tool upload or Git repository transfer and other methods, this article will demonstrate the use of Xftp and Git repository two ways to transfer code files. Xftp tools download address: www.netsarang.com/zh/xftp-dow…

Xftp is a powerful SFTP and FTP file transfer software. With Xftp, MS Windows users can securely transfer files between UNIX/Linux and Windows PCS.

After the installation is completed, you can open Xftp through XShell with one key. After Xftp is opened, you can switch the target path of the file to be uploaded on the right side of the software, and then drag the file to the right side to release it, and it will be uploaded automatically.

1.3. Use git repository for transfer

Compared with development, Git repository transfer is the recommended way to use. In frequent iterative updates, the operation process is a little cumbersome, including local compilation and release, and then copying files to the server. However, it is relatively simple to transfer through git repository. Developers only need to push the developed code to git repository, and then perform build, publish and other operations in the server, which reduces the tedious process of copying files, because build and publish are implemented in the server. You can write shell deployment scripts to achieve one-click rapid deployment.

To use Git, you need to install a Git client on the server and configure the SSH public key. The public key can be used to pull private repositories, but public repositories do not need to be configured.

The following explains the specific operation steps:

Install the Git client and run the following command:

yum -y install git
Copy the code

If an error occurs during the installation: cried’t resolve host

The DNS server is incorrectly configured. The solution is as follows: 1. Open the /etc/resolv.conf file and add:

2. Exit and restart the network:

service network restart

After git installation, run the following command to generate sshkey:

#Here [email protected] is only the name of the generated sshkey and does not restrict the goods to be named a specific mailbox.
ssh-keygen -t rsa -C "[email protected]"  
Copy the code

Press Enter three times as prompted to generate sSHKey, as shown below:

To view the public key, run the following command:

cat ~/.ssh/id_rsa.pub
Copy the code

Copy the generated sshkey and configure it into the public key of the code repository.

The public key has been generated. How do you configure it on the code hosting platform?

Next we’ll learn how to configure public keys on the Gitee code hosting platform (similar to Github).

Enter the [Management] page of the private warehouse, find [Public Key Management], and click [Add Public Key] to copy the public key just generated, as shown below:

If the command output similar to Hi XXX is displayed, the git public key is successfully configured.

ssh -T [email protected]
Copy the code

Confirm and add the host to the local SSH trusted list, as shown below:

If “Hi XXX” is displayed after you enter yes, the git public key is successfully configured.

2. Install.net Core SDK and runtime

We have made preparations before the deployment, installing Xshell, XFTP, Git, and configuring public keys for the repository.

Next we will install the.NET Core SDK on the Linux server.

The.NET runtime is. NET program to run the prerequisite, and SDK is not necessary, but if through Git file transfer, you need to go to the server side for compilation, so SDK also need to install. (Note: Docker deployment does not require SDK and runtime installation on the server, which will be introduced in a later article.)

Install the SDK and runtime in CentOs (see the official documentation for other environments: docs.microsoft.com/zh-cn/dotne…

Before installing.NET, we need to add the Microsoft package signing key to the trusted key list and add the Microsoft package repository. If you’ve installed it before. NET Core3.1, then this step can be omitted

Add the Microsoft package signing key to the trusted key list and add the Microsoft package repository by running the following command.

sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
Copy the code

Run the following command to install the SDK:

Sudo yum install -y dotnet-sdK-5.0Copy the code

The.NET Core SDK enables you to develop our applications through.NET Core.

After the installation is complete, you can verify the installation.

dotnet --info

Install the Netcore runtime using the following command:

Sudo yum install -y aspnetcore-runtime-5.0Copy the code

Note: the last 5.0 in the preceding command indicates the version number. If other versions such as 3.1 are installed, change the corresponding version number. Resources: dotnet.microsoft.com/download/do…

If the.net Core SDK has been installed, there is no need to install the corresponding runtime, where the SDK has been installed, and then the runtime will tell you that it has been installed, as shown below.

3. Publish the program to the server

In the previous preparation, we introduced two ways to publish files to the server, respectively: XFTP and git. Let’s demonstrate the methods and steps of these two ways respectively.

3.1. Publish to the server through Xftp

First, prepare your application for distribution. Here is one I created. NET5.0 sample code:

You can publish it by opening the VS package manager console and executing the following command:

 dotnet publish -o ./publish
Copy the code

You can also right-click the project to publish to a folder, as shown below.

The important thing to note here is the framework-dependent deployment pattern, as we’ve already installed it. NET Core environment, where independent deployment mode is not used, the default is “framework dependent”.

Framework-dependent deployment:

Framework dependent deployment (FDD) relies on the existence of a shared system-level version of.NET Core on the target system. Since.NET Core already exists, the application is also portable between.NET Core installers. The application contains only its own code and any third-party dependencies that reside outside the.NET Core library. FDD contains.dll files that can be launched from the command line using dotnet utilities. Dotnet app.dll, for example, can run an application called App. For FDD, only the application and third-party dependencies are deployed. There is no need to deploy.NET Core because the application will use the version of.NET Core that exists on the target system. This is the default deployment model for.NET Core and ASP.NET Core applications targeted to.NET Core

Advantages: (1) There is no need to define in advance the target operating system on which the.NET Core application will run. Because the executables and libraries of.NET Core are in the common PE file format regardless of the operating system,.net Core can execute applications regardless of the underlying operating system. ② Deployment packages are small. You only need to deploy the application and its dependencies, not.net Core itself. Many applications can use the same.NET Core installation, reducing disk space and memory usage on host systems.

Disadvantages: (1) The application will only run if the.net Core version or higher that you are targeting is already installed on the host system. .net Core runtime and libraries may change if future releases are not known. In rare cases, this can change the behavior of the application.

Independent deployment:

Independent deployment (SCD) does not depend on shared components that exist on the target system. All components, including the.NET Core library and the.NET Core runtime, are included in the application and are independent of other.NET Core applications. SCD includes an executable (such as app.exe for a Windows platform application called app), which is a renamed version of the platform-specific.NET Core host, and a.dll file (such as app.dll), which is the actual application. For standalone deployment, you can deploy the application and the required third-party dependencies and generate the VERSION of.NET Core used by the application. Creating an SCD does not include.net Core native dependencies on various platforms, so they must exist before running the application

The target system can run your.NET Core application because you provide the VERSION of.NET Core on which the application will run

Disadvantages: (1) Because.net Core is included in the deployment package, the target platform for which the deployment package is generated must be selected in advance. (2) The deployment package is relatively large because.net Core and applications and their third-party dependencies need to be included. Deploying a large number of independent.NET Core applications to the system may use a large amount of disk space because each application copies the.NET Core files

In the picture above you can see, after the Release of the path of the file as follows: the bin/Release/net5.0 / publish /

Open Xftp and drag the Publish folder to the window on the right of Xftp to complete the upload.

Switch to the published directory and start running, as shown in the picture below, successfully running.

You can also specify ports

# Start site, custom port number, run environment
dotnet Core50Test.dll --urls="http://*:8081; http://*:8082" --environment=Development
Copy the code

In this url configuration, if you need LAN or extranet access, you cannot fill urls=”http://localhost:8081; http://localhost:8082″

3.2. Release via Git

First, push the code to a Git repository and copy the SSH address. As shown below:

Then on the server, execute the clone command:

mkdir core50test
cd core50test
git clone [email protected]:******/core50test.git
Copy the code

The execution result is as follows:

Now that the project code has been downloaded to the server, switch the working directory to the directory where the solution resides.

cd core50test
Copy the code

Then run dotnet publish command to compile and publish the program.

 dotnet publish -o /yonghu/web/publish
Copy the code

After execution, the compiled and published files will be saved in the/YONGhu /web/publish directory.

Switch the working directory to/YONGhu /web/publish and run the following command:

dotnet core50test.dll
Copy the code

The execution result is shown as follows:

So far, our program is running on a Linux server.

From the introduction above, I believe that many of you have a deep understanding of the. Netcore project to Linux release, but these operations are still a little complicated, starting, stopping, picking and so on are handled separately. In the next article, we will introduce the use of Supervisor+Nginx through configuration. And shell scripts to achieve efficient deployment of.net Core.


Over the years, thanks to supporters and users of the RDIFramework.NET framework, you can find out more at the following address.

RDIFramework.NET official website: www.rdiframework.net/

RDIFramework.NET official blog: blog.rdiframework.net/

Special note, the framework related technical articles please refer to the official website prevail, welcome everyone to collect!

RDIFramework.NET is built by the professional team of Hainan Guosi Software Technology Co., LTD., which has been updated for a long time. Please feel free to use it!

Please follow the official wechat account of RDIFramework.NET (wechat id: Guosisoft) to keep abreast of the latest developments.

Use wechat to scan the QR code for immediate attention