Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of .NET Core Cross-platform Development

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you the "sample Analysis of .NET Core Cross-platform Development", which is easy to understand and well-organized. I hope it can help you solve your doubts. Let the editor lead you to study and learn the article "sample Analysis of .NET Core Cross-platform Development".

People who must be interested in the .NET open source project are already eager to try, but there are not many people who actually use it for development. After all, it was not until this article was published that NET Core was released to the 1.0RC2 version. The official version is expected to take some time. And most people take a wait-and-see attitude, even though developers are still using the .NET Framework. Another point I have to say is that the progress of .NET open source is amazing, but the community construction still needs to be improved, and many supporting things are not complete. Java may lag behind .NET at the language level, but the community power of Java is far less powerful than .NET.

First, install SDK

.net Core release: https://www.microsoft.com/net/core

The .NET Core provides the core running components, and the modules to be used are obtained through NuGet. Development can be completely independent of the .NET Framework and platform. But the .NET Core is not as full-featured as the .NET Framework. WebForm in the field of Web has been abandoned. WinForm is no longer part of the open source program. If you want to use it carefully, after all, this is just the beginning.

Install SDK on 1.windows platform

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

Install SDK on 2.Linux platform (test system: Ubuntu 14)

Official instruction manual: 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 main points to pay attention to:

Ubuntu 16 did not install successfully using apt-get during the test. So far, only the Ubuntu14 test has been successful.

Direct use: the version obtained by apt-get install dotnet is not clear. The version number after installation seems to be the latest, but the project created is not up-to-date. Therefore, the version number is specified according to the official way when installing.

3. Complete the installation and conduct environmental testing

Use instructions:

The copy 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-x64yoli@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

Second, create HelloWord program

1. Create a console project:

Mkdir hwappcd hwappdotnet new

Use the dotnet new directive to quickly create a project.

Dotnet new-t Console creates a console project. At present, the project type can only create console projects, and there are no other optional types. It is hoped that more project templates can be created later.

Dotnet new-l C # uses the C # language to create projects. Currently, only C# and F# are supported.

Compile and run the project:

Dotnet restore

Dotnet run

Use dotnet resotre to restore package references

Use dotnet run to run the program

Compile code using dotnet build

Publish a project using dotnet publish

For more information about the instruction parameters, please see the help description of the instruction.

two。 Create a Web project

Since the create directive does not support the creation of a Web project, you cannot create it directly using the create directive, but of course you can create a project by creating a project.json manually, which is unwise. You can quickly create projects with the help of tools and templates.

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

You can directly use the Git tool to copy to local use.

Another thing to pay attention to:

The startup mode of dnx is no longer used in the new version, and it has all been changed to the dotnet instruction. The Web project starts in the same way as the Console project.

The running effect of Linux is as follows:

Third, use the editor

Quote the official slogan:

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.

It feels very apt to describe it, but it is estimated that a lot of people will be fooled. How can I develop VS if I don't need it? Officials say that all you need is a text editor. Will developers accept such a powerful VS without having to use a text editor to develop it? As far as I am concerned, only a small number of people are willing to change. After all, the vast majority are still developed on the Windows platform, and ultimately choose to use windows+VS development, may choose other platforms to release. This is very disadvantageous to the formation of tool chains for other platforms.

1. Install VSCode

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

Install the C# development support plug-in

Open VSCode and use Ctrl+P to call up the command bar and enter the installation instructions:

The copy code is as follows:

Ext install csharp

Plug-in official website: https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp

When the installation is complete, you will be prompted to restart VSCode, and you will be ready for development after restart.

two。 Use VSCode to compile and run the project

Use VSCode to open the created project folder. The default project does not have a .vscode folder. After opening it, it will be prompted in the message bar above. Click OK and the .vscode folder will be created automatically.

This folder contains:

Launch.json and tasks.json files are used to configure the debugger and debug instructions.

When you open the code file, you will find that there are a lot of abnormal information in the code. Generally, the referenced package is not loaded. You can use the restore instruction to restore the package or wait for the VSCode to load. You may be prompted to restore the package in the notification bar.

Debug and run with F5. The C # debugging plug-in provides several ways to start debugging. Using Web startup will automatically open the browser by default. Breakpoint debugging single-step tracking is not very different, daily development is sufficient.

The running effect is as shown in the figure:

Issues to pay attention to:

(1) if you skip the step of adding a debugger, there may be a compilation error. You only need launch.json to modify the corresponding parameters. Such as:

(2) Troubleshooting 'Error while installing .NET Core Debugger'

If prompted above, use dotnet-- info to see if you can output normal information, and if not, reinstall the supported version of .NET Core SDK. If you prompt restore to fail, check your network connection.

(3) on Windows platform, if the prompt cannot find Symbols, enable Portable PDBs

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

The above is all the content of the article "sample Analysis of .NET Core Cross-platform Development". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report