DEV Community

Cover image for Avalonia UI on Ubuntu: Getting Started
Carlos Fabara
Carlos Fabara

Posted on • Updated on

Avalonia UI on Ubuntu: Getting Started

Avalonia UI is a cross-platform UI framework available for Dotnet Core. It is a project part of the .Net Foundation. Its main appeal is to provide the ability to create desktop applications for Windows, Linux and MacOS with a single code base.

In this tutorial we will see how to install the Avalonia templates and create a blank application.

Installing templates

The first thing we need to do is installing the Avalonia Templates so the dotnet new command could use them when creating new applications.

You need to go to the following Github Repository Avalonia Templates for dotnet new and download the zip version. Alternatively, you could clone it to your machine if you have git installed.

Avalonia templates Github Repo

After you have unzipped the file in the location you prefer. It is needed to run the following command. Keep in mind the path you need to use is the route to the unzipped templates



dotnet new --install [path-to-templates-folder]


Enter fullscreen mode Exit fullscreen mode

Tip: An easy way to add the folder path to the command line is to drag and drop the folder from the File Explorer

Drag and drop folder to the terminal

Creating an Avalonia application

The command executed on the previous step adds a few more templates to the dotnet new command.

There are two project templates added are the following:

  • avalonia.app: To create a barebones Avalonia application
  • avalonia.mvvm: To create an application that uses the Model-View-ViewModel pattern with ReactiveUI

To create a new application you need to run the following command:



dotnet new avalonia.app -o MyApp


Enter fullscreen mode Exit fullscreen mode

Where MyApp is the name of the application we are creating.

Running the application

To run the application you need to get into the MyApp folder



cd MyApp


Enter fullscreen mode Exit fullscreen mode

and then run the app with the dotnet CLI



dotnet run


Enter fullscreen mode Exit fullscreen mode

The result will be the following as a blank app shows on screen.

Blank Avalonia App

I hope you find this useful. In following entries we will continue exploring the Avalonia UI framework.

Top comments (8)

Collapse
 
thelordchosen profile image
Thelordchosen

On xubuntu 20.1

i am getting from dotnet run:::
Unhandled exception. System.TypeInitializationException: The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.
---> System.DllNotFoundException: Unable to load shared library 'libSkiaSharp' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibSkiaSharp: cannot open shared object file: No such file or directory

what i am doing wrong ?

Collapse
 
muhammadsulaiman001 profile image
Muhammad Sulaiman

This solves the issue for me

sudo apt install libice6
sudo apt install libsm6
sudo apt install libfontconfig1
Enter fullscreen mode Exit fullscreen mode

Source

Collapse
 
carlos487 profile image
Carlos Fabara

Are you able to run any other dotnet app console/web? It might be due to XFCE too, maybe a library is missing.

Collapse
 
thelordchosen profile image
Thelordchosen

yes after so much google i narrowed down my problem to this

github.com/mono/SkiaSharp/issues/1050
but none of the solutions helped me

Thread Thread
 
thelordchosen profile image
Thelordchosen

for anyone in future who run into the same problem this stackoverflow answer may help

stackoverflow.com/questions/685828...

Collapse
 
freestyler profile image
Alex

Thx, but:
How build release version?
What final size of release version this simple app?
What contain directory of release version?
Simplicity of building and final size very crucial for cross-platform development, to compete w/ others solutions likes Electron and Flutter

Collapse
 
freestyler profile image
Alex • Edited

How install dotnet on Ubuntu 22? apt install dotnet-host ?

Collapse
 
xpyctajleb profile image
Xpyctajleb

On the step dotnet new --install [path-to-templates-folder] :
Segmantation fault (Core dumped)