We continue the series of articles about working with FastReport Avalonia in Visual Studio Code on various operating systems. In this article, we will analyze in detail how to run FastReport Avalonia on a Linux operating system using the Visual Studio Code IDE.
Avalonia UI is a .NET framework that is actively used for developing cross-platform user interfaces. With its universal API for application building, Avalonia supports all major platforms and runtime environments and has its unique interface. This ensures that your business solutions will look identical on every operating system.
FastReport Avalonia includes a powerful data processing engine, a familiar report designer, and a viewer for generated reports. Additionally, the new product supports all export formats of the built reports, such as PDF, Excel, MS Word, and many others.
The library is fully backward compatible with FastReport WPF, FastReport .NET, and FastReport Mono. It supports Avalonia UI, .NET 7, and .NET 8.
First, we need to install Visual Studio Code from the official website. Download the latest version of Visual Studio Code.
The next step is to install .NET 8 itself. To do this, you can go to the official Microsoft website and download the installer for Linux.
We need to install Avalonia templates for further work. To do this, we need to open the console and enter the following command:
dotnet new install Avalonia.Templates
Next, open Visual Studio Code and configure it. Go to the Extensions tab. We need to install the following extensions: .NET Install Tool, Avalonia for Visual Studio Code, and C#.
After installing the necessary extensions, we need to connect a private NuGet server to install the required FastReport packages. You can learn how to use a private NuGet server by following this link.
Once we have completed these steps, we can start creating the project.
To create an Avalonia project, open Visual Studio Code. Since we have installed the necessary templates and extensions, we should have a “Create Avalonia Project” button. Click on it. Then, select “Avalonia App” and specify the project name. Let’s name it “FastReportAvalonia.” Choose the directory where the project will be stored.
After creating the project, you may encounter an error when installing .NET 8 in the project. You can fix it by following these steps:
1) In the error window, click on “Configure Manager”;
2) Explicitly specify the path to .NET 8. For example: /usr/share/dotnet/dotnet.
In different distributions, the storage path of .NET 8 may vary, so please take this into account in your project.
After that, we need to connect FastReport packages. To do this, open the .csproj file and add the following lines:
<PackageReference Include=”FastReport.Avalonia” Version=”2024.1.9” /> <PackageReference Include=”FastReport.Forms.Avalonia” Version=”2024.1.9” />
Our file should look something like this:
Next, go to the MainWindow.axaml file and add a button.
<Button Click =”ButtonClicked”> Start </Button>
The code in the file should look something like this:
The next step is to write the logic for the button. To do this, open the MainWindow.axaml.cs file and create an event.
using FastReport; ….. public void ButtonClicked(object source, RoutedEventArgs args) { Report report = new Report(); report.Load(“Отчет.frx”); report.Design(); }
Now we can run our application. For debugging, we need to use .NET 5+. After launching, a window with a “Start” button will appear. Click on it, and the designer will launch.
We can also enable preview and view the report in Preview mode.
Thus, we were able to run FastReport Avalonia on Linux using Visual Studio Code. As you can see, there is nothing complicated in the setup and launch process. It is enough to install the SDK packages, and configure private NuGet packages, and then you can use FastReport Avalonia. If you have any questions, please contact our technical support at support@fast-report.com. Enjoy using FastReport Avalonia!