dotnet Core Command Detailed

Source: Internet
Author: User
Tags dotnet net command net command line xunit

This blog to learn about Dotnet's Magical command. I'll turn to dotnet,dotnet new,dotnet restore,dotnet build,dotnet test,dotnet run,dotnet Publish the use of these commands to make a simple introduction and demo. dotnet

The dotnet command is primarily used to view some basic information, such as platform, version number, and so on. The parameters that are often used are –version,–info,–help, run below to see the output

Dotnet–version
1.0.0-preview2-003121
Dotnet–info
. NET Command Line Tools (1.0.0-preview2-003121)

Product Information:
version:1.0.0-preview2-003121
Commit SHA-1 Hash:1e9d529bc5

Runtime Environment:
OS name:mac os X
OS version:10.11
OS Platform:darwin
Rid:osx.10.11-x64
Dotnet–help
. NET Command Line Tools (1.0.0-preview2-003121)
usage:dotnet [host-options] [command] [arguments] [common-options]

Arguments:
[Command] The command to execute
[Arguments] Arguments to the command
[Host-options] Options specific to dotnet (host)
[Common-options] Options common to all commands

Common options:
-v|–verbose Enable Verbose output
-h|–help Show Help

Host options (passed before the command):
-v|–verbose Enable Verbose output
–version Display. NET CLI Version number
–info Display. NET CLI Info

Common Commands:
New Initialize a basic. NET Project
Restore restore dependencies specified in the. NET Project
Build builds a. NET project
Publish publishes A. NET Project for deployment (including the runtime)
Run compiles and immediately executes a. NET Project
Test runs unit tests using the test runner specified in the project
Pack creates a NuGet package dotnet New

The dotnet new command is used to create a. NET core project that contains two options, either-t (or –type) and-L (or-lang), which specify the project type and programming language.

-l,–lang [c#| F #]
The default value of-L is C #, or it can be set to F #. VB words should soon be able to support.

-t,–type [Console|web|lib|xunittest]
The default value for-T is concole, the console item. Several other parameters represent Web projects, class library projects, and test projects. For example, the dotnet New command creates a console project, and dotnet NEW-T Web creates a Web project (asp.net mvc). dotnet Restore

dotnet restore [–source] [–packages] [–disable-parallel] [–fallbacksource] [–configfile]
[–verbosity] []
The dotnet Restore command downloads the dependencies defined in the Project.json file by NuGet and puts them in the. nuget/packages folder in the user directory. By default, the process of downloading dependent builds is done in parallel.
The –packages option specifies where the downloaded component resides, by default to the. nuget/packages folder under the user's directory.
The –disable-parallel option is used to disable concurrent downloads.
The –configfile option specifies which nuget.config file to use.
When the dotnet Restore command is complete, a Project.lock.json file is generated. dotnet Build

Dotnet Build [–output] [–build-base-path] [–framework] [–configuration] [–runtime] [–version-suffix]
[– Build-profile] [–no-incremental] [–no-dependencies] [] The
dotnet build command compiles all the source code files and dependent components in the project into binary DLL files. The command reads Project.lock.json, and if the file is not found in the project, the dotnet Restore command needs to be run first.
After the dotnet build command is completed, the. dll file and the. pbd file are generated under the bin/debug/netcoreapp1.0 folder, for example:

bash-3.2$ ls-al bin/debug/netcoreapp1.0/
Total
drwxr-xr-x jingjing Staff 374 9 6 22:08.
Drwxr-xr-x 6 Jingjing Staff 204 9 6 21:52.
-rw-r–r–@ 1 jingjing staff 6148 9 6 23:13. Ds_store
-rwxr–r–1 jingjing staff 1636 9 5 22:38 App.deps.json
-rwxr–r–1 jingjing staff 4608 9 5 22:38 App.dll
-rwxr–r–1 jingjing Staff 496 9 5 22:38 app.pdb
-rwxr–r–1 jingjing Staff 9 5 22:38 APP.RUNTIMECONFIG.DEV.J Son
-rwxr–r–1 jingjing staff 118 9 5 22:38 App.runtimeconfig.json
-rwxr–r–1 jingjing staff 3584 9 5 22:05 Libr Ary.dll
-rwxr–r–1 jingjing Staff 452 9 5 22:05 library.pdb
Drwxr-xr-x Ten Jingjing staff 9 6 22:08 Publish Strong>dotnet Test

dotnet test [–configuration] [–output] [–build-base-path] [–framework] [–runtime] [–no-build] [–parentprocessid]
[–port] []
The dotnet Test command is used to run the test code in a unit test project, which relies on a unit test framework (such as NUnit or xunit) and the corresponding unit test run. The unit test runtime is specified by the Testrunner node in the Project.json file. The following is a Project.json file for a project that uses Xunit as a unit test framework

{
  "version": "1.0.0-*",
  "Buildoptions": {
    "debugtype": "Portable"
  },
  "dependencies": {
    " System.Runtime.Serialization.Primitives ":" 4.1.1 ","
    xunit ":" 2.1.0 ",
    " Dotnet-test-xunit ":" 1.0.0- Rc2-192208-24 "
  },
  " Testrunner ":" Xunit ",
  " frameworks ": {"
    netcoreapp1.0 ": {"
      dependencies " : {"
        Microsoft.NETCore.App": {"
          type": "Platform",
          "version": "1.0.0"
        }
      },
      "Imports" : [
        ' dotnet5.4 ',
        ' Portable-net451+win8 '
      ]
  }
}}

Among them, "Testrunner": "Xunit" refers to the required unit test run. dotnet Run

dotnet Run [–framework] [–configuration] [–project] [–help] [–]
The dotnet Run command is a relatively handy command to run code. It compiles the code, outputs the information, and runs the code. dotnet Pack

dotnet Pack [–output] [–no-build] [–build-base-path] [–configuration] [–version-suffix] []
The dotnet Pack command compiles the code and generates a NuGet package, specifically, to generate a. nupkg file and a. symbols.nupkg file in the Bin\Debug directory. dotnet Publish

dotnet Publish [–framework] [–runtime] [–build-base-path] [–output] [–version-suffix] [–configuration] []
The dotnet Publish command compiles the code and then reads all the dependent components defined in the Project.json file, and then outputs the items to a folder. The generated file is output to \bin\debug\netcoreapp1.0\publish by default, and you can modify the output location by using the-O or –output options. When you need to publish your code, the output file for the command will be all the files you need.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.