A Brief Introduction to. NET Core cross-platform development,. netcore

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

A Brief Introduction to. NET Core cross-platform development,. netcore

For the. NET open-source program, there may be few people who are interested in it. After all, as of the time of this article,. NET Core was released to 1.0RC2. The official version is expected to be available for a while. In addition, most people are holding a wait-and-see attitude, even if the development is still using. NET Framework. In addition, the progress of. NET open source is amazing, but the Community Construction still needs to be improved, and many supporting items are not complete yet. Java may lag behind. NET at the language level, but Java's Community power is far from. NET.

1. Install the SDK

. NET Core Release: https://www.microsoft.com/net/core

. NET Core provides Core running components, and all modules used are obtained through NuGet. Development can be completely independent of. NET Framework and platform. However,. NET Core is not as full as. NET Framework. WebForm in the Web field has been abandoned. Currently, WinForm is no longer open-source. I want to use it with caution. After all, this is just the beginning.

1. Install the SDK on windows

Download and install it directly. Https://go.microsoft.com/fwlink? LinkID = 798398

2. Install the SDK on the Linux platform(The testing system is Ubuntu 14)

Official Guide: https://www.microsoft.com/net/core#ubuntu

sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list'sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893sudo apt-get updatesudo apt-get install dotnet-dev-1.0.0-preview1-002702

There are several notes:

Ubuntu 16 fails to be installed with apt-get during testing. Currently, the test is successful only in Ubuntu14.

Directly use: the version obtained by apt-get install dotnet is unclear. It seems that the version number after installation is the latest, but the created project is not the latest. Therefore, the official version number is specified during installation.

3. environment testing is completed after installation.

Instructions:

Copy codeThe Code is as follows: dotnet -- info

The test results are as follows:

C:\>dotnet --info.NET Command Line Tools (1.0.0-preview1-002702)Product Information: Version:   1.0.0-preview1-002702 Commit Sha: 6cde21225eRuntime Environment: OS Name:   Windows OS Version: 10.0.10586 OS Platform: Windows RID:     win10-x64
yoli@ubuntu:~$ dotnet --info.NET Command Line Tools (1.0.0-preview1-002702)Product Information: Version:   1.0.0-preview1-002702 Commit Sha: 6cde21225eRuntime Environment: OS Name:   ubuntu OS Version: 14.04 OS Platform: Linux RID:     ubuntu.14.04-x64

2. Create a HelloWord Program

1. Create a console project:

mkdir hwappcd hwappdotnet new

Use the dotnet new command to quickly create a project.

Dotnet new-t Console creates a Console project. Currently, only console projects can be created for the project type, and no other optional types are available. You want to create more project templates later.

Dotnet new-l C # Use the C # language to create a project. Currently, only C # And F # are supported #.

Compile and run the project:

Copy codeThe Code is as follows: dotnet restore
Dotnet run

Use dotnet resotre to restore package reference

Run the program using dotnet run

Use dotnet build to compile code

Use dotnet publish to publish a project

For detailed instruction parameters, see instructions for instructions.

2. Create a Web Project

Because the creation command does not support creating Web projects, you cannot directly use the creation command to create them. Of course, you can create a project by manually creating project. json. This is unwise. You can use some tools and templates to quickly create a project.

Available template case: https://github.com/aspnet/cli-samples

You can directly use the Git tool to copy it to your local computer.

Note the following:

The dnx startup method is no longer used in the new version. All commands are changed to the dotnet command. The Web project is started in the same way as the Console project.

Linux runs as follows:

3. Use the editor

Reference the official promotional slogans:

It is very easy to get started with .NET Core on your platform of choice.You just need a shell, a text editor and 10 minutes of your time.

I feel like it is very relevant, but it is estimated that there will be a lot of people forced. How can we develop VS without having to use it? The official saying is that only one text editor is needed. Do developers accept the powerful VS development without using a text editor? For me, only a few people are willing to change. After all, most of them are still developed on the Windows platform. In the end, they are still developed using windows + VS. Other platforms may be used for release. This is very unfavorable for the formation of tool chains on other platforms.

1. Install VSCode

Download and install VSCode: https://www.visualstudio.com/en-us/products/code-vs.aspx.

Install C # development support plug-in

Open VSCode, press Ctrl + P to bring up the command bar, and enter the installation command:

Copy codeThe Code is as follows: ext install csharp

Agent Official Website: https://marketplace.visualstudio.com/items? ItemName = ms-vscode.csharp

After the installation is complete, you will be prompted to restart VSCode. After the restart, you can start development.

2. Use VSCode to compile and run the project

Use VSCode to open the created project folder. The default project does not have the. vscode folder. After opening the folder, a message box is displayed in the upper part. Click OK to create the. vscode folder automatically.

This folder contains:

launch.jsonAndtasks.jsonThese two files are used to configure the debugger and debug commands.

When you open the code file, you will find that the Code has a lot of exception information. Generally, the referenced package is not loaded. You can use the restore command to restore it or wait until the VSCode is loaded. You may be prompted in the notification bar to restore the package.

Use F5 for debugging. C # The debugging plug-in provides the following methods to start debugging. Web boot automatically opens the browser by default. The basic difference between breakpoint debugging and single-step tracking is not very big, and it is enough for daily development.

Running Effect

Notes:

(1) If you skip the step of adding a debugger, an error may be reported during compilation. You only need to modify the corresponding parameters in launch. json. For example:

(2) Troubleshooting 'error while installing. NET Core debugger'

If the above prompt is displayed, use dotnet -- info to check whether the normal information can be output. If not, reinstall the supported version of. NET Core SDK. If the system prompts a restore failure, check the network connection.

(3) On Windows, if you are prompted that the Symbols cannot be found, enable Portable PDBs

Open project. json, find buildOptions, and change debugType to portable. If the buildOptions option cannot be found, the name is compilationOptions in the old version.

Conclusion: The Open Source of. NET is more helpless than Microsoft's kindness. In addition, VSCode has much room for improvement in text editing and multi-project management. There are still many gaps in community construction, and we hope to add them as soon as possible. Every time I read the document and see the words In the future, hasn' t been written yet and so on, it is always an inexplicable sense of loss.

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