Computer

Create .NET programs with Uno Platform: same code for all platforms

Create .NET programs with Uno Platform: same code for all platforms

While from May 1, 2024, Microsoft has announced the end of support for Xamarin, Uno Platform confirms itself as one of the best solutions for creare app .NET for web, mobile, desktop and embedded devices using the same programming code. Uno Platform stands out for its impressive range of features and focus on productivity and flexibility, to create .NET programs that “just work” on all platforms, without the need to make changes to the code.

The platform is open source and is capable of adapting to the needs of each programmer. For example, developers can decide to use their favorite tools. Whether it’s Visual Studio, Visual Studio Code, or Rider, Uno Platform offers a seamless development experience. Thanks to the built-in support for C# and XAML Hot Reloadyou can create and test the user interfaces in real time, significantly improving productivity.

One of the distinctive elements of Uno Platform is the integration with Figma, a popular design tool. Developers can easily export designs from Figma and generate quickly markup in C# or XAML so as to faithfully reflect the original design.

What is Uno Platform and what are its purposes

As explained in the introduction, Uno Platform for .NET is a technology that enables the development of applications cross-platformallowing you to create a single codebase which can run on platforms like iOS, Android, Windows, macOS, Linux e Web. Each developer can therefore write code only once and deploy it across multiple devices and operating systems.

Supported Platforms Uno Platform

Uno Platform takes advantage of the API .NET to ensure a smooth development experience and build user interfaces responsive and performing. Thanks to its architecture, it allows you to create native applications that maintain a consistent appearance and behavior across different platforms, minimizing the need to write specific code for each operating system.

From hundreds of available .NET UI components to native Windows features, Uno Platform gives developers all the tools needed to build high-quality, best-performing apps.

Support for XAML, a declarative language for designing user interfaces, facilitates the creation of flexible layouts that adapt to different screens and resolutions. This approach allows developers to focus on application logic, reducing development time and improving efficiency. However, you can also use C# markup.

How Uno Platform works, in brief

We said that Uno Platform is designed to allow the same application code to run on all supported platforms, ensuring a consistent experience for users regardless of the device used.

On Windows, the application is compiled using the tool Windows App SDK, without involving Uno Platform. In essence, the program created by the developer is treated as an application WinUI single-platform. The heart of Uno Platform is Uno.UI, a NuGet package that fully reproduces the WinUI API, including all namespaces, classes, and class members. This way, you can replicate the look and behavior of your application across all platforms while maintaining a consistent public API.

When rendering the user interface, XAML elements are converted into elements HTML for the Web, in displayed natively for iOS and Mac Catalyst, for Android and directly in the form of canvas Skia per Linux.

When compiling the application, Uno Platform handles various aspects. Let’s mention, for example, the generation of binary file of applications, parsing XAML elements, and converting resources such as images and strings to the appropriate formats for each target platform. XAML files are converted to C# code using a code generator Roslynfacilitating the development process without requiring manual intervention.

Get started with Uno Platform

To try the many updates recently applied to the platform, simply configure your operating system and your preferred integrated development environment (IDE). Uno Platform offers support for a wide range of operating systems and IDEs: from the project’s official website, click on Develop then on the preferred development environment to carry out the download of the add-on to install.

Per install Uno Platform in Visual Studioit is necessary to enable the components in the figure and then add the extension from the appropriate menu, as indicated in the support document Get started on Visual Studio 2022.

One Platform, Visual Studio installation to create .NET programs

Making use of the contribution of Windows Subsystem for Linux (WSL), you can run Linux on Windows and test all the applications you are developing in real time. The steps to enable support for Skia desktop projects differ depending on the Linux distribution installed in WSL. The commands to be given to configure the work environment, however, can be found on the page available on the Uno Platform website.

Even in the case of Visual Studio Codejust install the Uno Platform extension (also add OpenJDK 11 for Android application development on Linux).

In any case, to verify the correct functioning of the platform, the following commands can be given from the Windows command line:

dotnet tool install -g uno.check

dotnet tool update -g uno.check

uno-check

The steps to follow are very similar, apart from minimal differences, on macOS and Linux.

Create .NET programs with the IDE you like best

To request the creation of a .NET app from Visual Studio just launch a new project then select the item Uno Platform App. The platform offers several models to prepare the skeleton of the program you intend to create.

Create .NET program with Uno Platform

In the case of Visual Studio Code, however, it is necessary to use the Live Wizard from the web browser. Also in this case, it is possible to assign a name to the project being created and then move on to choosing the template.

Use Uno Platform from Visual Studio Code

The application can then be opened by navigating to the location that contains it, then typing code ./MyApp (specifying, obviously, the correct name of the program).

More information on writing the application with Uno Platform is available in the official documentation.

Leave a Reply

Your email address will not be published. Required fields are marked *