Home  >  Article  >  Backend Development  >  How to use dotnet command?

How to use dotnet command?

零下一度
零下一度Original
2017-06-23 16:07:056096browse

The following examples are used to string together common dotnet commands to help you play with dotnet commands.

1. Create (dotnet new)

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.

2. Restore (dotnet restore and dotnet pack)

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.

3. Run (dotnet build and dotnet run)

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:

4. Test (dotnet test)

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

5. Publish (dotnet publish)

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 win10-x64;ubuntu.14.04-x64

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn