How to work with FastReport Avalonia on .NET 8 in Visual Studio for Mac

2024-03-26

Avalonia UI is a .NET-based framework widely used for cross-platform user interface development. With a universal API for building applications, Avalonia supports all major platforms and runtime environments and has its unique interface. This ensures that your business solutions will look identical on each operating system.

FastReport Avalonia includes a powerful data processing core, a familiar report designer, and a viewer for ready-made reports. Additionally, the new product supports all export formats for the generated report, 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.

In this article, we will explain in detail how to run FastReport Avalonia on the MacOS operating system using the Visual Studio IDE.

 

Preparatory stage

First of all, we need to install Visual Studio for Mac. A specific version of Visual Studio is required for further work with Avalonia templates, namely 17.6.10. You can download it by following this link. It enables you to include .NET 8 support, which we will discuss a little later.

The next step will be installing .NET 8 itself. For this, you can go to the official Microsoft website and download the installer for MacOS.

Choosing the SDK for further work

After installing SDK 8.0, we need to configure Visual Studio. To work with .NET 8, we need to enable its usage in Visual Studio. To do this, right-click on Visual Studio and select "Preferences".

Visual Studio Settings

In the opened window, scroll down to the bottom until you reach the "Preview Features" section and check the box next to the "Use the .NET 8 SDK..." option.

Visual Studio Settings

Click "OK" and restart Visual Studio.

After going through the above steps, we need to install Avalonia templates for further work. Once installed, we can choose ready-made templates in Visual Studio to streamline the development process. To do this, open the console and enter the following command:

dotnet new install Avalonia.Templates

Now we can start creating a project in Visual Studio.

 

Creating the Application

Launch Visual Studio and create a new project. When selecting a template, scroll down to the "Other" group and choose "Custom." In the window, select the "Avalonia .NET app" template. These are the templates we installed using the console command. Click on Continue.

Creating a new project using Avalonia UI

Next, we need to configure the template. Choose the .NET and Avalonia versions. We recommend selecting Avalonia version 11.1.0-beta or higher, as many visual bugs have been fixed in this version. For our example, let's stick with .NET 8. Click on "Continue."

Configuring the New Project

Now, we have an Avalonia template project in Visual Studio. Next, we need to connect a private NuGet server where we can obtain Avalonia NuGet packages. To do this, right-click on our project and select "Manage NuGet Packages...".

Configuring the New Project

Connecting NuGet Packages to the Project

In the window that appears, at the very end, there is "Package source: All sources". Expand the list and click on "Configure Sources...".

Connecting NuGet Packages to the Project

In the window that appears, click on "Add". A window for entering data will appear.
- Name: source name without spaces (e.g., FastReport-Nuget);
- Location: https://nuget.fast-report.com/api/v3/index.json;
- Username: email from your Fast Reports account;
- Password: password from your Fast Reports account.

Connecting to the NuGet Server

Once we have entered all the necessary data, we can close the window. Now, we have a private NuGet server that we can use.

The next step is to add the required packages for the project, namely: FastReport.Avalonia and FastReport.Forms.Avalonia.

To do this, in the NuGet Package window, select our private NuGet server as the package source. For convenience, we will type "Avalonia" in the search box to display packages with the corresponding name. Select the desired packages and install them.

Connecting FastReport NuGet packages

Now that we have configured the project, we can proceed with writing the code. Next, let's consider a simple example to demonstrate the functionality of the FastReport Avalonia packages. First, open the MainWindow.axaml.cs file and fill it in as follows:

using Avalonia.Controls;
using Avalonia.Interactivity;
using FastReport;
namespace FRAvalonia;
public partial class MainWindow : Window
{
 public MainWindow()
 {
 InitializeComponent();
 }
 public void ButtonClicked(object source, RoutedEventArgs args)
 {
 Report report = new Report();
 report.Load("Barcode.frx");
 report.Design();
 }
}

So far, we have simply added a method to handle the button and specified which report will be opened in the designer.

Next, go to MainWindow.axaml and fill it in as follows:

<Window xmlns="https://github.com/avaloniaui"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 x:Class="FRAvalonia.MainWindow"
 Title="FRAvalonia">
 <Button Click="ButtonClicked" >Start Designer!</Button>
</Window>

Next, we add the button itself, which already has a handler assigned to it. Now, we can run the project.

Upon running the project, a window with a button will appear. Click on the button and observe the magic as the FastReport Designer on Avalonia launches.

FastReport Avalonia Designer

Additionally, we can enable the preview mode and take a look at the report in the Preview.

Report Preview

In this way, we managed to run FastReport Avalonia on MacOS using Visual Studio. As you can see, there is nothing complex about the setup and launch process. Just install the SDK packages, configure the private NuGet packages, and you can start using FastReport Avalonia. If you have any questions, please feel free to contact our technical support at support@fast-report.com. Enjoy using it!

August 12, 2024

How to build and install the Postgres plugin in FastReport .NET

This article describes how to connect to the database using the FastReport .NET plugin for the report designer from Visual Studio via the NuGet server.
August 08, 2024

How to install FastReport .NET and its components on Windows

Step-by-step instructions for online and manual installation via the FastReport registration code.NET and its components in Windows.
July 26, 2024

Updating HTMLObject as a plugin for FastReport .NET

Detailed instructions for using the new HTMLObject plugin, which uses splitting DOM HTML into FastReport report objects.
Fast Reports
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314

© 1998-2024 Fast Reports Inc.