How to set up an C# Markup project for Toolkit

UnoFeatures: CSharpMarkup (add to <UnoFeatures> in your .csproj)

In this tutorial, you'll learn how to set up an Uno Platform project to use C# Markup.

  1. Make sure your environment is set up properly by using uno check.

  2. You can create a Uno App by either using the Uno Platform Visual Studio extension or via the command line interface.

    Using Visual Studio 2022 Uno Platform Extension

    • Open the Visual Studio and select Extensions => Manage Extensions and Search (Ctrl + E) for unoplatform.

    • Make sure you have the latest version of Uno Extension (v5.0 or higher) installed.

      Screenshot displaying how to check the version of the Uno Extension wizard version in Visual Studio extension manager

    • Press Ctrl+Shift+N to create a new project and select "Uno Platform App".

    • Give your project an appropriate name (MySampleToolkitProject in this page).

    • When prompted Select Blank and click Customize

      Screenshot displaying the intro screen of the Uno Extension wizard in Visual Studio

    • In the Markup tab (4rd one), select C# Markup.

      Screenshot displaying how to pre-install C# Markup in the generated project

    • In the Features tab (7rd one), select Toolkit.

      Screenshot displaying how to pre-install Toolkit in the generated project

    • Click Create on the bottom right corner.

Toolkit References

Note: The recommended way to add Toolkit to your project is using the Toolkit UnoFeature in your .csproj file.

Looking in detail at the projects with the addition of the Toolkit, we can see the addition of some additional references. This shows what happens when you enable the Toolkit UnoFeature, which automatically adds the necessary package references.

When using the Toolkit UnoFeature, the following packages are automatically included:

  1. Package versions in Directory.Packages.props:

    <PackageVersion Include="Uno.Toolkit.WinUI" Version="0.0.0" />
    <PackageVersion Include="Uno.Toolkit.WinUI.Markup" Version="0.0.0" />
    
  2. Package references added to the following projects:

    • PROJECT_NAME.Wasm.csproj
    • PROJECT_NAME.Mobile.csproj (or PROJECT_NAME.iOS.csproj, PROJECT_NAME.Droid.csproj, PROJECT_NAME.macOS.csproj if you have an existing project)
    • PROJECT_NAME.Skia.Gtk.csproj
    • PROJECT_NAME.Windows.csproj (or PROJECT_NAME.UWP.csproj for existing projects)
    <PackageReference Include="Uno.Toolkit.WinUI.Markup" />
    

The UnoFeature automatically chooses:

  • The Uno.Toolkit.UI package when targeting Xamarin/UWP
  • The Uno.Toolkit.WinUI package when targeting net6.0+/WinUI