NET Core Environment Build and command line CLI Getting started [go]

Source: Internet
Author: User
Tags dot net dotnet

NET Core Environment Build and command line CLI entry time:2016-07-06 01:48:19 read:258 comments:0 Favorites:0 [Point I collection +]

NET Core Environment Build and command line CLI Getting Started

June 27, 2016. NET Core & ASP 1.0 was officially released at the Redhat summit, and there were a lot of articles in the community, and I was planning to write a series of articles because the. NET core entry threshold was quite high, and it was necessary to write a series of articles in a comprehensible The contents of this section help you get started. I will probably use Windows as a development environment or LINUX/MAC, but all dotnet CLI commands are cross-platform, and we develop cross-platform applications on the WINDOWS/LINUX/MAC platform.

Install the. NET Core

. NET core includes the. NET core Runtime and the. NET Core SDK:

    1. . NET core = Application Run dependent. NET Core runtime
    2. . NET core SDK = using. NET core Development app. NET Core Runtime and SDK+CLI (software development kit/command line Interface) tools

Please go to dotnet official website (dot dot net), very good to remember, this site is also your introductory. NET core portal, remember that this is a must go to the site. The specific address of the. NET core Download: https://, here are a few things to note:

    1. Although the. NET core runtime and the base library are already 1.0 RTM, the development toolchain (. NET core cli,visual Studio and Visual Studio Code) is a preview version, see HTTPS://BLOGS.MSDN .
    2. To deploy an app on Windows servers, you can install ASP. NET Core Module for IIS separately without installing the. can be dotnetcore.1.0.0-windowshosting.exe by command line opt_install_redist=0
    3. The minimum requirements for MAC systems are MacOS 10.11 (El Capitan)
    4. . NET Core Support for RHEL 7 server on Red Hat series servers, including CentOS 7 above, see Https://
    5. . NET Core Support on Ubuntu requires Ubuntu 14.04 lts and Ubuntu 16.04 LTS
    6. If you have previously installed the BETA,RC1,RC2 version of. NET core, you need to uninstall them before installing, see the article in the stack overflow.

The specific installation method for. NET core can be see the article. NET Core series: 1, the environment is built.

dotnet Command Line Interface (CLI)

The dotnet command-line interface (CLI) of. NET Core is important, a set of tools that we develop and operate, and Microsoft provides us with this command-line tool for use in our development programs, primarily for compiling code, managing NuGet packages, program run, test, and so on. Simply put: When a newcomer sits in his seat and begins to learn node, Python, Ruby, Golang, or anything else, for the vast majority of people, that's what they're supposed to do with their experience. Use. NET should be seen as an easy and simple thing to do. Partners who learn and use. NET have the same experience on go or ruby. In this article, the. NET Core dotnet Command Daquan Describes how to use the command line, and the dotnet Run command describes the dotnet Run command in more detail. Practice examples can be used in the article through a few Hello world to feel. NET core new development experience.

We're going to go through a Hello World example to learn the next dotnet command line, we've installed. NET Core 1.0 and can do the following:

>dotnet New
>dotnet Restore
>dotnet Run

Imagine being with me when you compare this with the Visual Studio code that runs on Mac, Windows, and Linux, then you've got a very exciting story. It's easy to run open source. NET code in many places.

Here is a long code, create a console application, as long as the top of the input "dotnet", you can get a lot of things to use.

[Email protected] helloworld]# dotnet

Microsoft. NET Core Shared Framework Host


usage:dotnet [common-options] [options] Path-to-application

Common Options:
--help Display. NET Core Shared Framework Host help.
--version Display. NET Core Shared Framework Host version.

--fx-version <version> version of the installed Shared Framework to use to run the application.
--additionalprobingpath <path> path containing probing policy and assemblies to probe for.

Path to Application:
The path to a. NET Core managed application, DLL, or EXE file to execute.

If You is debugging the Shared Framework Host, set ' Corehost_trace ' to ' 1 ' in your environment.

To get started on developing applications for. NET Core, install the. NET SDK from:

[Email protected] ~]# mkdir HelloWorld
[Email protected] ~]# CD HelloWorld
[Email protected] helloworld]# dotnet New
Created New C # project In/root/helloworld.
[[email protected] helloworld]# ls
Program.cs Project.json
[Email protected] helloworld]# VI Program.cs
[Email protected] helloworld]# dotnet Restore
Log:restoring Packages For/root/helloworld/project.json ...
log:writing lock file to disk. Path:/root/helloworld/project.lock.json
Log:restore completed in 2277ms.
[[email protected] helloworld]# dotnet Run
Project HelloWorld (. netcoreapp,version=v1.0) 'll be compiled because expected outputs is missing
Compiling HelloWorld for. netcoreapp,version=v1.0

Compilation succeeded.
0 Warning (s)
0 Error (s)

TIME Elapsed 00:00:03.0002808

Hello world!
[Email protected] helloworld]#

With these basic commands above, we run our. NET Core applications.

dotnet New

The new command is used to create the. NET project or an application

[Email protected] ~]# dotnet new--help
. NET Initializer

Usage:dotnet new [Options]

-h|--help Show Help Information
-l|--lang <LANGUAGE> LANGUAGE of Project [c#| F #]
-t|--type <TYPE> type of Project

You can use this command to create several different types of application types that support the C # and f#,c# language supported project types as follows:

    • Console
    • Web
    • Library
    • XUnit Test

dotnet Restore

The restore command uses NuGet to restore dependencies and project-specific tools that are defined in the project file Project.json.

[Email protected] ~]# dotnet restore--help

Usage:nuget3 restore [arguments] [options]

[Root] List of projects and project folders to restore.                                                          Each value can be:a path to a Project.json or Global.json file, or a folder to recursively search fo R project.json files.

-h|--help Show Help Information
--force-english-output forces the application to run using a invariant, english-based culture.
-s|--source <source> Specifies a NuGet package source to use during the restore.
--packages <packagesDirectory> Directory to install packages in.
--disable-parallel disables restoring multiple projects in parallel.
-f|--fallbacksource <FEED> A list of packages sources to use as A fallback.
--configfile <file> The NuGet configuration file to use.
--no-cache does not cache packages and HTTP requests.
--infer-runtimes temporary option to allow NuGet to infer rids for legacy repositories
-v|--verbosity <verbosity> The verbosity of logging to use. Allowed Values:debug, Verbose, information, Minimal, Warning, Error.
--ignore-failed-sources only warning failed sources if there is packages meeting version requirement
[Email protected] ~]#

As you can see from the "Usage:" line above, the restore command only calls to the Nuget3 executable, typically you do not need to modify these options if you are using a custom package source, either because you are using a pre-release version of the Microsoft library or your organization uses its own package source, You may need to specify a package source that uses the-s parameter.

Run the dotnet restore to generate a lock file (Project.json.lock) that includes detailed information about all the packages that were recovered.

dotnet Build

The build command compiles the project and the project that he depends on into a binary file, by default the binaries are intermediate Language (IL) and. dll for the file name extension. The compilation process relies on the existence of a lock file (Project.json.lock), which is generated by the restore command.

In order to build an executable application, you need to ensure that the project configuration's compilation options set the entry point of the app:

"Buildoptions": {    "emitentrypoint": True  },
> dotnet builderusage:dotnet Build [arguments] [options]arguments:<project> the PROJECT to COM Pile, defaults to the current directory. Can be one or multiple paths to Project.json, project directory or globbing patter that matches Project.json filesoptions: -h|--help Show help Information-o|--output <OUTPUT_DIR> Directory in which to P Lace Outputs-b|--build-base-path <OUTPUT_DIR> Directory in which to place temporary outputs-f|--framework <fram Ework> Compile a specific framework-r|--runtime <RUNTIME_IDENTIFIER> produce runtime-specific assets F or the specified runtime-c|--configuration <CONFIGURATION> configuration under which to Build--version-suffix <                     version_suffix> defines what ' * ' should is replaced with on version field in Project.json--build-profile Set this flag to print the incremental safety checks that prevent incremental compilation--no-incrEmental set this flag to turn off incremental build--no-dependencies set this flag to Ignore project to project references and only build the root project

You can use the-F option to specify that you want to compile into a specific framework. This framework must be defined in the project file. The-c option allows you to specify the configuration to use. It will default to debug, but you can specify it as release.

Dotnet Run

In most cases, you skip the restore,build above and run the program directly using the dotnet Run command, whether or not the application is modified, to recompile the build app and run it.

> dotnet run --help.NET Run CommandUsage: dotnet run [options] [[--] <arg>...]]Options:-h|--help           Show help information-f|--framework      Compile a specific framework-c|--configuration  Configuration under which to build-p|--project        The path to the project to run (defaults to the current directory). Can be a path to a project.json or a project directory
Dotnet Run command describes the dotnet Run command in more detail


Run using the provided framework, which is the project.json frameworks node in the corresponding file

-C,--configuration [debug| Release]

Configure whether the environment used is debug or Release, the default is debug mode.

-P,--project [PATH]

Specifies the project to run, which can be a file path, which can be a project.json contained project.json path, and, if not specified, the current path by default.

dotnet [AssemblyName]

You can run the compiled application with the dotnet command and pass the application path as a parameter to the dotnet command

> dotnet. \bin\debug\netcoreapp1.0\helloworld.dll
Hello world!

Dotnet Pack

The pack command compiles the project and generates a NuGet package that generates two NuGet packages:

    • An assembly file that includes compiled code
    • An assembly file that includes debug symbols and compiled code

Project-dependent NuGet projects are added to the build Nuspec file, and the reference relationship between projects is not packaged by default, but can be changed by changing the project's dependency type.

dotnet Publish

The Publish command compiles the application and reads the project file, and then publishes the file of the result set to a directory. The content of the build directory will depend on the type of project, but it can include a cross-platform IL application and his dependencies, which is commonly used by the portable deployment, where the application shares the. NET core runtime environment and assembly dependencies, and the deployment of the target machine requires the prior installation of the. NET Core SDK, and then run the program with the dotnet command. Either a subfolder of each native platform or a self-contained application that includes the runtime of the target platform, which is how self-contained is deployed. The self-contained deployment approach is that each application comes with a. NET core runtime environment and an assembly dependency, and the deployed target machine does not need to install the. NET core SDK to copy the application folder to run. Refer to the documentation for specific reference documentation. NET Core Application Deployment

The default Project.json compiled application does not include cross-platform, need to modify Project.json file, need to Add runtimes node in Project.json to comment out "type": "Platform".

  "version": "1.0.0-*",
  "buildoptions": {
    "debugtype": "Portable",
    "Emitentrypoint": True
  "dependencies": {"Hwapp": "1.0.0"},
  " Frameworks ": {
   " netcoreapp1.0 ": {
     " dependencies ": {
        "Microsoft.NETCore.App": {
           "version": "1.0.0"
      "Imports": "Dnxcore50"

"Runtimes": {
"Win7-x64": {},
"Win7-x86": {},
"Osx.10.10-x64": {},
"Osx.10.11-x64": {},
"Ubuntu.14.04-x64": {},
"Centos.7-x64": {}


First we want to dotnet restore, Here I restore some long time, we wait patiently, because we set up 4 platforms.

dotnet Publish-r centos.7-x64

This build deployment file can be cross-platform, build Linux deployment Files on Windows with the dotnet publish-r centos.7-x64 command, and then upload the entire deployment folder to the Linux server.

dotnet Test

The test command is used to run the test project, using the test suite defined in the configured Test Runner. You will learn more about this command in the sections later in this tutorial for more detailed information.

Next time we'll take a closer look at the Project.json file and start trying to build a more complex application with the new. Net Core.

Original address:

NET Core Environment Build and command line CLI Getting started [go]

Related Article

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: 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.