Getting Started
Describes how to setup a MauiReactor project
Creating a new MauiReactor project from CLI
MauiReactor provides a convenient dotnet project template you can install to easily create a new dotnet maui project with MauiReactor bindings:
To create a new project just issue
To build the project just move inside the project directory and run the usual dotnet build command like this (in the example below we'll use the android target, the same applies to the other targets like net9.0-ios, net9.0-maccatalyst, or windows10.0.19041.0):
To run the app under the Android platform execute the following command:
Install MauiReactor hot-reload console
MauiReactor also provides a Hot-Reload console program that automatically hot reloads the project you are working on as you save changes to any file.
To install it, just type the following command in the terminal:
If you want to upgrade the tool to the latest version run the command:
Finally, you have to modify the project definition by adding the following lines:
MauiReactor hot-reload console
MauiReactor hot reload can work in two different modes: Simple and Full
To start the hot-reload console in Simple Mode:
This is the command to start it in Full Mode:
This is the typical startup messages from the hot-reload tool:
Under MacOS, ensure that your app is NOT executed in "sandbox mode" otherwise, hot-reload won't work.
Go to Platforms->MacCatalyst->Entitlements.plist and set/update this value:
Please note that before publishing to the App Store this value must be set to true again.
.NET built-in hot-reload
MauiReactor also supports .NET built-in hot-reload. This feature is enabled by default when you call the MauiReactor.HotReload
feature is set.
Create a new project in Visual Studio 2022
After you have installed the dotnet project template you should see it in the Visual Studio project creation dialog:
Migrate from the default MAUI project template
It's fine to start from a standard MAUI project template: below we'll see what is required to migrate a brand-new project to MauiReactor. This short guide also helps to make a port from an existing MVVM project to MauiReactor.
Step 1
Include the latest version of the MauiReactor package (select the latest version):
Even if not strictly required, I suggest removing the ImplicitUsings directive in the csproj file:
and add a GlobalUsings.cs file containing these global usings:
This will avoid problems with namespacing conflicts between MAUI and MauiReactor.
Step 2
Remove the file App.xaml, AppShell.xaml, and MainPage.xaml (including the code-behind files).
Step 3
Create a MainPage component: add a HomePage.cs file in the project root folder with this code:
Step 4
Finally, replace the Program.cs main content:
Best practices
When the app is hot-reloaded, a new assembly is compiled on the fly and injected into the running app. This means that the new component lives in a different assembly from the original one. It's recommended to follow these best practices to avoid type mismatch issues:
Component state class should contain only public properties whose types are value-type or string.
If you need a component state with properties other than value-type/string (i.e. classes), host them in a separate assembly (project) so that it's not hot reloaded.
Last updated
Was this helpful?