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!

November 20, 2024

Localization and Language Switching in FastReport VCL

FastReport VCL supports 40 languages for interface localization and allows you to change the language on the fly through menus or code, without recompilation.
November 01, 2024

New Features of the FastReport VCL Editor

We are considering new features of the report editor: extension lines, highlighting of intersecting objects, updated report and data trees.
October 30, 2024

Using Styles When Creating Reports in FastReport VCL

The article discusses one of the new features of FastReport VCL — the use of styles and style sheets.
Fast Reports
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 66 Canal Center Plaza, Ste 505, Alexandria, VA 22314

© 1998-2024 Fast Reports Inc.