Home > Article > Backend Development > How to use dotnet command?
The following examples are used to string together common dotnet commands to help you play with dotnet commands.
First we create a project, here we create a console program, the command is as shown in the figure below.
dotnet new
dotnet new For more parameters, please refer to the help dotnet new -h.
Then create a class lib, which is the class library. The command is as shown in the figure below.
dotnet new classlib
After creating it, write some of your own code and package it.
Two methods are written here, now let’s package them.
dotnet restore
dotnet pack
How does .NET Core add an offline reference package? Now the answer is revealed.
After packaging, add applib to the app’s app.csproj.
Add the following in app.csproj:
After adding it, switch to the app directory and restore it.
The command used for restoration is: dotnet restore -s E:\dotnet\applib\bin\Debug\, which is the path of the dotnet restore -s package.
In this way, you can directly call the methods in applib in the project.
Write the corresponding call in the code, and then execute the program. You can see that the result of class lib is correctly output.
Take app as an example.
dotnet build compiles the code, and then dotnet run executes the program:
dotnet app.dll is also the execution program:
Create a new folder and project here.
New test project: dotnet new xunit.
After creating a new project, you can add test methods in it and run the test directly here.
dotnet restore
dotnet test
Publish the project so that it can run across platforms.
dotnet publish is published by default.
After publishing, navigate to the publish directory and use dotnet app.dll to execute the application.
Let’s publish cross-platform.
Open app.csproj and add
First we need to dotnet restore. The restoration may take a while, so please be patient.
dotnet publish -r win10-x64
After publishing here, you can directly navigate to the publish directory and execute app.exe That’s it.
dotnet publish -r ubuntu.14.04-x64
Upload the publish folder to the Linux system and set the App permissions to Executable, then ./app can be run.
dotnet publish –r: Specify the system ID in the RuntimeIdentifiers node.
From creating new files to publishing actual dotnet commands, you will have a better understanding of dotnet commands.
This article is an update to "ASP.NET Core Cross-Platform Development from Getting Started to Practical Practice" 2.9 dotnet command practice, and is also an update to the previous blog post .NET Core dotnet command collection.
Time flies really fast. The last article was actually a year ago. The update of .NET Core has made some of the content no longer applicable. I hope the new content can help you.
If you think this article is helpful to you, please click "Recommend", thank you.
The above is the detailed content of How to use dotnet command?. For more information, please follow other related articles on the PHP Chinese website!