Use the CMD command line (. Net core CLI) to start ASP.NET Multiple instances of core applications

Time:2020-11-30

This chapter mainly shares with you how to use the CMD command line (. Net core CLI) to start ASP.NET Multiple instances of the core application to simulate a cluster.

The. Net core command line interface (CLI) tool is a cross platform tool chain for developing, building, running and publishing. Net core applications.

The CLI command structure contains drivers (“dotnet”) and commands, and may also contain command parameters and options.

Let’s move on to the topic of this chapter

First, let’s build a MVC project (target framework: net core 3.1), as follows:

Enter the directory where the project file. Csproj is located

After inputting CMD, press enter key to quickly enter the specified directory

The dotnet run //. Net core cli command runs the source code without any explicit compile or start command.

Even if the startup is successful, use the dotnet run command to start. The default port number is launchSettings.json 5000 set in

Let’s use port 5000 to access the browser to see if it really started successfully

As you can see, the startup is successful

At this point, we can pressCtrl + CTo stop the program, the successful stop is as follows:

At this point, if you don’t want to use port 5000, you can use the — URLs command parameter to specify the specific port, for example:

dotnet run --urls=http://*:8080

The same operation will doOpen a few more command-line windows, so that you can do the same set of code, start different processes, listen to different ports, in order to simulate the cluster, as shown below.

Above, we have opened two CMD interfaces and started an instance with port numbers of 8080 and 8081 respectively. Now we can use these two port numbers to access

We can find that we have successfully accessed with these two port numbers

You can also run the specified project

dotnet run -p  NETCoreCLI.csproj  //A "- is the abbreviation of P
dotnet run --project  NETCoreCLI.csproj  //The two "- are the full name of the project

Enter here NETCoreCLI.csproj There is a little trick, is to enter an n afterPress the tab key and it will be filled automaticallyIn this way, you don’t have to input word by word.

PS: special attention should be paid to the starting mode described above. Once the program code is modified, you need to use Ctrl + C to stop and restart.

Of course, the trick is to addwatchAutomatic monitoring program code changes, once modified the code will automatically restart.

dotnet watch run -p NETCoreCLI.csproj --urls=http://*:8080

In addition, there is a command that is mainly used to start the application after publishing, as shown below:

PS: use this command to start. Once the code is modified, you need to stop, then regenerate the release, and finally restart.

Dotnet [DLL file under solution bin file] - URLs = http: // *: 8080

dotnet NETCoreCLI.dll --urls=http://*:8080

If you use this command to directly start an application that has not been published, some resource files may not be accessible, as follows:

At this time, although the startup is successful, some resources cannot be accessed, as shown below:

Therefore, this command is mainly used to start the application after the release, as shown below:

First of all, we will publish the project, click Project = > Right Click = > select publish

Select IIS, FTP, etc

Select File System

Then publish it

Finally, use the commandLaunch post release application

You can see that the boot is successful

PS:

Using the command line to start a program can also support attaching to the process for debugging. You can try the W3 wp.exe perhaps dotnet.exe Or the application. Exe is attached to the process for debugging.

The application program. Exe is as follows:

This paper deals with theSummary of. Net core cli commands

dotnet run
Dotnet run -- URLs = http: // *: 8080 // URLs specifies the IP and port
The dotnet watch run / watch listener is modified. If it is modified, it will be restarted
dotnet watch run --urls=http://*:8080
dotnet run -p  NETCoreCLI.csproj   //A "- is the abbreviation of P
dotnet run --project  NETCoreCLI.csproj   //The two "- are the full name of the project
dotnet watch run -p NETCoreCLI.csproj --urls=http://*:8080
Dotnet [DLL file under solution bin file] - URLs = http: // *: 8080
dotnet NETCoreCLI.dll --urls=http://*:8080
Dotnet clean // clears the default generation of the project, which has the same effect as the right-click cleanup in vs
CTRL + C // stop
CLS // clear screen
Tab // auto fill

PS:

For details of. Net core cli, please refer to the official website: https://docs.microsoft.com/zh-cn/dotnet/core/tools/dotnet-run

 

This article is carefully written by bloggers, please keep the original link:https://www.cnblogs.com/xyh9039/p/13155059.html

Copyright notice: if there is any similarity, please contact me to modify it in time, thank you!!!