Dotnet, work with .NET on Ubuntu 18.04 and create your first application

about dot net

In the next article we are going to take a look at the .NET kernel. This is a free, cross-platform and open source framework developed by Microsoft to create desktop apps, mobile apps, web apps, game apps, etc.

If you are a .NET developer, coming from the Windows platform, the .NET kernel will help you to configure your development environment easily, on any Gnu / Linux and Unix operating system. In the following lines we will see how install Microsoft .NET Core SDK on Ubuntu 18.04 and how to write the first application using donet.

Install Microsoft .NET Core SDK on Ubuntu 18.04

The .NET kernel is compatible with GNU / Linux, Mac OS, and Windows. It can be installed on the most popular GNU / Linux operating systems, including: Debian, Fedora, CentOS, Oracle Linux, RHEL, SUSE, and Ubuntu.

To begin we are going to open a terminal (Ctrl + Alt + T) and type the following commands:

download microsoft .net and install on Ubuntu

wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb

sudo dpkg -i packages-microsoft-prod.deb

As well we will need to enable the 'Universe' repository, if you don't have it enabled yet. This can be done by typing in the terminal:

sudo add-apt-repository universe

Now you can install .NET core SDK using the commands:

install apt-transport-https

sudo apt install apt-transport-https

install dotnet sdk 2.2

sudo apt update && sudo apt install dotnet-sdk-2.2

After the installation, we can check the installed version typing:

dotnet version

dotnet --version

Creating your first application with dotnet

As you can see, the core SDK of .NET has been installed correctly in our Ubuntu. Now is the time to create the first application using dotnet.

As an example I will create a new application called 'ubunlogApp'. To do this, you just have to open a terminal (Ctrl + Alt + T) and run:

Create console application with dotnet

dotnet new console -o ubunlogApp

As you can see in the screenshot above, dotnet has created a new console type application. The -o parameter creates a directory called 'ubunlogApp'where the application data is stored with all the necessary files.

If we move to the directory ubunlogApp we will find something like the following:

files from an application created with dotnet

There are two files called ubunlogApp.csproj and Program.cs and a directory called obj. By default, the Program.cs file will contain the code to run the program 'Bonjour Monde'on the console. We can take a look at the program code by typing:

hello world dotnet program.cs file

cat Program.cs

If we want run the application we just created, you just have to write the following command:

hello world dotnet terminal result

dotnet run

The "Hello World puedo cambiarloTypical is that simple. Now, anyone can write their code in Program.cs file and run it in the same way.

Another thing we can do is create a new directory, for example, my code, using the commands:

mkdir ~/.micodigo

cd ~/.micodigo/

… And from there we can make this directory our new development environment executing the following command:

dotnet app my code

dotnet new console

The above command will create two files called mycode.csproj and Program.cs plus a directory called obj. Now we can open the Program.cs file in an editor and delete or modify the existing 'hello world' code with our own code.

Once the code we want is written, we just have to save and close the Program.cs file. After this we can run the app:

dotnet run

It can consult dotnet help typing:

dotnet --help

Microsoft Visual Studio Code Editor

To write the code, everyone has their favorite editor. But it must be said that Microsoft has its own editor called 'Microsoft Visual Studio Code'with support for .NET. This is a cross-platform code editor, so it can be used both on Windows, GNU / Linux, and on Mac OS X.

It is a lightweight and powerful open source source code editor. It comes with built-in support for JavaScript, TypeScript, and Node.js and has a rich ecosystem of extensions for other languages ​​like C ++, C, Python, PHP, or Go.

If you are interested in using this code editor to develop your applications with .NET, you can consult the article that a colleague wrote in which he indicated how install Visual Studio Code in Ubuntu.

In the Microsoft documentation we will be able to find some basic tutorials to learn how to use the .NET Core and .NET Core SDK tools using the Visual Studio Code editor.

For learn more about dotnet, you can consult the official project page.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Luis Gonzalez said

    I am with Lubuntu and in the first installation line it tells me that there is no microsoft package. Is there an inconsistency with this distro ?. Greetings

  2.   Christian Carvajal said

    After creating my application, how do I install it in Ubuntu?

  3.   Authorless said

    Good Luis, add the repo?