Dotnet command practice and dotnet practice
The following example is a string of common dotnet commands to show you how to use dotnet commands.
1. Create (dotnet new)
First, create a project. Here we create a console program, as shown in the command.
Dotnet new
For more information about dotnet new parameters, see help dotnet new-h.
2. restore (dotnet restore and dotnet pack)
Create a class lib, that is, the class library, as shown in the command.
Dotnet new classlib
After the creation, write your own code and then package it.
Two methods are compiled here. Now we can package them.
Dotnet restore
Dotnet pack
How does. NET Core add offline reference packages? Answer now.
After packaging, add applib to app. csproj of the app.
Add the following in app. csproj:
<ItemGroup>
<PackageReference Include = "applib" Version = "1.0.0"/>
</ItemGroup>
After adding the file, switch to the app directory and restore the file.
The restore command is dotnet restore-s E: \ dotnet \ applib \ bin \ Debug \, that is, the path of the dotnet restore-s package.
In this way, the method in applib can be called directly in the project.
Write the corresponding call in the code and then execute the program. The result of class lib is output correctly.
3. run (dotnet build and dotnet run)
Take app as an example.
Dotnet build to compile the code, and then dotnet run to execute the program:
Dotnet app. dll is also the execution program:
4. test (dotnet test)
Create a folder and project.
Create a test project: dotnet new xunit.
After creating a project, you can add a test method to it. Here, you can run the test directly.
Dotnet restore
Dotnet test
5. publish (dotnet publish)
Publish a project so that it can run across platforms.
Dotnet publish is released by default.
After the release, go to the publish directory and use dotnet app. dll to execute the application.
The following is a cross-platform release.
Open app. csproj and add the <RuntimeIdentifiers> win10-x64; ubuntu.14.04-x64 </RuntimeIdentifiers> to the PropertyGroup node.
First, we need dotnet restore. The Restoration may take some time, so please wait patiently.
Dotnet publish-r win10-x64
After publishing, you can directly locate the publish directory and execute app.exe.
Dotnet publish-r ubuntu.14.04-x64
Upload the publish folder to Linux, set the App permission to executable, and then run the./app.
Dotnet publish-r: Specifies the System ID in the RuntimeIdentifiers node.
From the creation to the release of the actual dotnet command, more familiar with the dotnet command.
This article updates the practice of the 2.9 dotnet command in ASP. NET Core cross-platform development from getting started to practice, and also updates the previous blog. NET Core dotnet command book.
Time is really fast. The previous article was an article a year ago. The update of. NET Core makes some content no longer applicable. I hope the new content will help you.
If you think this article is helpful to you, click"Recommendation", Thank you.