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

How to get started with .NET for Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

In this issue, the editor will bring you about how to get started with .NET for Linux. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Basically, when you know what a programmer's preferred operating system is, you can guess what programming language they are using. For example, if a programmer is using Windows, the list of languages they may use includes Clipper journal JavaScript and TypeScript, if he is a more traditional programmer, he may use Visual Basic, if he is a programmer who keeps abreast of the times, he may be using F# If they are using Linux, you will also get a list of open source projects: Go,Python,Ruby,Rails,Grails,Node.js,Haskell,Elixir and so on, and of course we can't ignore the newly emerging language-Kotlin.

However, Microsoft broke the situation with a move to make the NET framework and create. NET Core, which can be run on any platform, such as Windows,Linux,MacOS, or even on Samsung Tizen, a mobile operating system. Given this situation, Linux programmers should familiarize themselves with. NET Core as soon as possible and try to use it to build production applications.

How to install .NET Core on Linux

Linux distributions that can run. NET Core include Red Hat EnterpriseLinux (RHEL), Ubuntu,Debian,Fedora,CentOS,Oracle, and SUSE.

Each distribution has its own installation instructions. This article takes Fedora 26 as an example:

Step 1: add dotnet product feed.

Sudo rpm-- import https:// packages.microsoft.com / keys / microsoft.asc

Sudo sh-c'echo-e "[packages-microsoft-com-prod] nname = packages-microsoft-com-prod nbaseurl = https://packages.microsoft.com/yumrepos/microsoft-rhel7.3-prod nenabled = 1 ngpgcheck = 1 ngpgkey = https://packages.microsoft.com/keys/microsoft.asc" > / etc / yum.repos.d/dotnetdev.repo "

Step 2: install the .NET Core SDK.

Sudo dnf update

Sudo dnf install libunwind libicu compat-openssl10

Sudo dnf install dotnet-sdk-2.0.0

Create a Hello World console application

After the .NET Core is installed, the next step is to create the "Hello World" console application.

Output:

Let's analyze what the above code does.

Dotnew new console

There is no doubt that everyone knows that it created "Hello World!" For console applications, it should be noted that the project name needs to match the directory name; the code is built using templates (console applications); and the project dependencies are automatically retrieved by the dotnet restore command extracted from nuget.org.

If you look at the directory, you will see that some files have been created:

Program.cs

Helloworld.csproj

Program.cs is the C# console application code, and Helloworld.csproj is a MSBuild-compatible project file that takes on a new meaning when creating a Web service or Web site.

Dotnet run

This command does two things: create the code and run the newly created code. Whenever dotnet run is called, it checks to see if the * .csproj file has been changed and runs the dotnet restore command. It also checks to see if any source code has been changed and runs the dotnet build command in the background to build the executable. Finally, it runs the executable.

Where is the executable file?

The following is the path to the executable:

/ opt/rh/rh-dotnet20/root/usr/bin/dotnet

When you create a. Net application, component, or library, you are also creating a DLL. If you want to see what the dotnet build command creates, you can take a look at bin / Debug / netcoreapp2.0 /, which includes the helloworld.dll,JSON configuration file, and the helloworld.pdb (debug database) file, as well as the JSON file.

Run dotnet run, running the process is dotnet. The process invokes the DLL file and becomes the application.

Portable application program

This is where the .NET Core really starts to move away from the Windows-only .NET Framework: the DLL you just created can run on any system with. NET Core installed, whether it's Linux,Windows or MacOS. It is portable, so it is called "portable application".

Stand-alone application

What if you want to distribute an application but don't want users to install .NET Core on their machines? the .NET Core has a way: stand-alone applications.

Creating a stand-alone application means that you can distribute the application to any system and run it without installing the .NET Core. This means faster and easier installation, and it also means that you can have multiple applications running different versions of .NET Core on the same system.

Areas for improvement

When you use the dotnet publish command to create a stand-alone application, DLL is placed in the target directory along with all. Net bits that must run DLL. In other words, you can see 50 files in the directory. But this problem will also change soon, and the .NET Native, which is already in the experiment, will soon be introduced and released in the .NET Core. It will build an executable file that contains all the bits, just like the Go language compilation, you can specify the target platform and get the executable file.

Build a release for RHEL 7.x on a 64-bit processor:

Dotnet publish-c Release-r rhel.7-x64

Web service, website...

The .NET Core template contains more, including support for F# and Visual Basic. To get a list of available templates built into the .NET Core, you can use the command dotnet new-- help.

Tip: .NET Core templates can be created by a third party.

As with most command-line tools, contextual help is available at any time using the-- help command.

The above is the editor for you to share how to get started with the .NET for Linux, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are 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

Servers

Wechat

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

12
Report