Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to develop with. Net on Linux

Shulou Source: shulou.com Published: 2022-06-01 11:08:13 10月25日 Update

This article focuses on "how to develop with. Net on Linux". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to develop with. Net on Linux.

How to install .NET

The .NET download is divided into several packages: one contains only the .NET runtime, and the other .NET SDK contains the .NET Core and runtime. Depending on the architecture and operating system version, there may be multiple versions of these packages. To start using .NET for development, you must install the SDK. It provides you with dotnet terminals or PowerShell commands that you can use to create and build projects.

Linux

To install .NET on Linux, first add the Microsoft Linux software repository to your computer.

On Fedora:

$sudo rpm-- import https://packages.microsoft.com/keys/microsoft.asc$ sudo wget-Q-O / etc/yum.repos.d/microsoft-prod.repo https://packages.microsoft.com/config/fedora/27/prod.repo

On Ubuntu:

$wget-Q https://packages.microsoft.com/config/ubuntu/19.04/packages-microsoft-prod.deb-O packages-microsoft-prod.deb$ sudo dpkg-I packages-microsoft-prod.deb

Next, install SDK using the package manager, which will be replaced with the current version of .NET:

On Fedora:

$sudo dnf install dotnet-sdk-

On Ubuntu:

$sudo apt install apt-transport-https$ sudo apt update$ sudo apt install dotnet-sdk-

After downloading and installing all packages, open the terminal and enter the following command to confirm the installation:

$dotnet-versionX.Y.ZWindows

If you are using Microsoft Windows, you may have installed the .NET runtime. However, to develop .NET applications, you must also install the .NET Core SDK.

First, download the installer. Please make sure to download .NET Core for cross-platform development (.NET Framework is only available for Windows). After downloading the .exe file, double-click the file to start the installation wizard, and then double-click to install: accept the license and allow the installation to continue.

Installing dotnet on Windows

Then, open PowerShell from the applications menu in the lower left corner. In PowerShell, enter the test command:

PS C:\ Users\ osdc > dotnet

If you see information about dotnet installation, .NET is installed correctly.

MacOS

If you are using Apple Mac, please download the .pkg Mac installer. Download and double-click the .pkg file, and then click setup. You may need to grant permissions to the installer because the package is not from App Store.

After downloading and installing all the packages, open the terminal and enter the following command to confirm the installation:

$dotnet-- versionX.Y.ZHello .NET

The dotnet command provides a "hello world" sample program written in .NET. Or, more accurately, the command provides a sample application.

First, create a project directory and required code infrastructure for the console application using the dotnet command and the new and console parameters. Use the-o option to specify the project name:

$dotnet new console-o hellodotnet

This will create a directory called hellodotnet in the current directory. Go to your project directory and take a look:

$cd hellodotnet$ dirhellodotnet.csproj obj Program.cs

Program.cs is an empty C # file that contains a simple Hello World program. Open it in a text editor to view it. Microsoft's Visual Studio Code is a cross-platform open source application written in dotnet, and although it's not a bad text editor, it collects a lot of data from users (it grants itself permissions in its binary distribution license). If you are trying to use Visual Studio Code, consider using VSCodium, which is built using Visual Studio Code's MIT-licensed source code without remote collection (read this document to disable other forms of tracking in this build). Or, just use your existing favorite text editor or IDE.

The boilerplate code in the new console application is:

Using System; namespace hellodotnet {class Program {static void Main (string [] args) {Console.WriteLine ("Hello World!");}

To run the program, use the dotnet run command:

$dotnet runHello World!

This is the basic workflow of .NET and dotnet commands.

At this point, I believe you have a deeper understanding of "how to develop with .NET on Linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Commands programs development applications versions files directories projects runs text terminals editors software Microsoft input code content multiple forms console Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Docker Shulou Information Shulou Technology vpn