Small white. Net Core 2.0 ConsoleApp Primer (Keng) Guide (i)

Source: Internet
Author: User
Tags dotnet

First, the preparatory work

The preparation is simple, even without visual Studio, a. NET core and runtime (have you considered the world's first IDE experience)

Download: https://www.microsoft.com/net/download/windows

All the way next beep Doodle install ....

Second, generate a ConsoleApp project

How about producing project files without vs? It's really simple, just need a cmd.

1). Summon cmd (win+r input cmd).

2). Open a CMD and enter the following command ("E" Here is the project name)

1 New console-o e2 cd E

When you're done, you'll see Program.cs and E.csproj, which indicates that the build was successful

Third, the operation

Open Program.cs with any text tool you will see the following auto-generated code

1 usingSystem;2 3 namespacee4 {5     class Program6     {7         Static voidMain (string[] args)8         {9Console.WriteLine ("Hello world!");Ten         } One     } A}

Here we'll use the simplest Hello world to do the example

In the cmd window, type:

1 dotnet Run

Simple Bar ~

You can now see our first. NET Core program!

Iv. Release

There are two modes of publishing for. Net Core:

They are respectively

    • Portable applications (portable application, need to install runtime, small size, Hello world about 5kb)
    • Self-contained application (self-hosting application, comes with runtime, large volume, Hello world about 65MB) << See 65M distressed? Don't worry, you can "slim down" after the release is complete see: https://www.cnblogs.com/yunei/p/7436368.html (Author: Woo Cloud)

1). Publish the Portable app:

Super simple, you just need to type in cmd

1 dotnet publish-c release

Ready, post file in: \bin\release\netcoreapp2.0\publish\

2). Publish the self-hosted app:

Here need to set up the operating environment, the supported platform has been added a lot, the mainstream has WIN,LINUX,OSX, etc., here to win and Linux for example (because it is too poor to use OSX, interested in small partners can try)

1). Open the project file e.csproj. Some code has been generated automatically at this time

<ProjectSDK= "MICROSOFT.NET.SDK">  <PropertyGroup>    <OutputType>Exe</OutputType>    <targetframework>netcoreapp2.0</targetframework>  </PropertyGroup></Project>

We need to add items in their PropertyGroup key <runtimeidentifiers>linux-x64;win-x64;osx-x64</runtimeidentifiers> , namely:

<ProjectSDK= "MICROSOFT.NET.SDK">  <PropertyGroup>    <OutputType>Exe</OutputType>    <targetframework>netcoreapp2.0</targetframework>    <runtimeidentifiers>Linux-x64;win-x64;osx-x64</runtimeidentifiers>  </PropertyGroup></Project>

Enter in CMD (the linux-x64 in the code can be replaced with the items added above, such as: Win-x64 or osx-x64):

dotnet Publish-r:linux-x64-c Release

Post-completion files in Bin\release\netcoreapp2.0\linux-x64\publish

V. Running 1. Portable Applications: Windows

Directly click EXE to run, haha

Linux and OSX

1). Need to install. NET core Runtime Download: https://www.microsoft.com/net/download/windows (note the version number and system)

2). At the command prompt, enter dotnet your file name for example: Dotnet E (here in Ubuntu 16.04 x64 example)

PS: Allow files to run as a program if they do not work

2. Self-hosted app: Windows

Directly click EXE to run, haha

Linux and OSX

1). Allow files to be executed as programs

2). At the command prompt, enter the./your file name for example:./E

Run successfully! (Platform: linux-x64 system: Ubuntu16.04 x64)

This article is over, I hope you will support me a lot

If you have any questions, please contact my penguin number 2728578956 (code: 25432)

Small white. Net Core 2.0 ConsoleApp Primer (Keng) Guide (i)

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.