Migrating Projects to Single Project
The Uno Platform 5.2 and later use the Uno.Sdk which provides a single Uno Project structure and a single location for updating the Uno Platform core packages version in global.json.
Important
Migrating to the Uno.Sdk and Single Project are not required. Existing projects, 5.1 and earlier, continue to be supported in Uno Platform 5.2 or later.
With Uno Platform Single Project, you can optimize your project structure and simplify maintenance while leveraging the power of Uno Platform for cross-platform app development. This guide provides step-by-step instructions and practical tips to ensure a smooth migration process. Let's get started!
What is the Uno.Sdk
The Uno.Sdk is used to abstract the complexity needed to build cross-platform projects, while still ensuring that you have the ability to customize the configuration to your needs.
This means that values such as the SupportedOSPlatformVersion, which have been in the template's Directory.Build.props in previous Uno Platform templates, now have a default value set to the minimum supported by Uno Platform.
If you need to be more restrictive for your specific project you can provide your overrides for the platform(s) that you need.
Project Structure
In the Uno Platform Single Project, all platform-specific code is put together in one project. Instead of having separate projects for each platform, everything is organized within a Platforms folder. This folder contains sub-folders for each platform your project targets, like Android, iOS, Skia, WebAssembly, and Windows. Each platform folder stores the code and resources needed for that platform, making development easier to manage for multi-platform projects.
Upgrading an existing project to Single Project
The following sections detail how to upgrade an existing project to use a single project with the Uno.Sdk. Those modifications are made in place and it is strongly recommended to work on a source-controlled environment.
While following this guide, you can compare with a new empty project created using our Wizard, or using dotnet new templates.
Migrating to a Single Project
Migrating from a 5.1 or earlier template is a matter of merging all the csproj files for all the platforms heads down to one csproj file.
We'll take the example of an Uno Platform 5.0 blank app, called MyApp, to migrate to Single Project :
In a separate folder from your existing app, create a new app using the same name as your app:
dotnet new unoapp -o MyApp --preset=recommendedThis will allow for taking pieces of the structure with the proper namespaces. If your app was created using the blank template, use
--preset=blankinstead. You can also use the Live Wizard or the Visual Studio Wizard and select the same optional features you used for your app.Next to the solution, create a
global.jsonfile{ "msbuild-sdks": { "Uno.Sdk": "{Current Version of Uno.WinUI/Uno.Sdk}" } }From the empty app created at step one:
- Take the contents of the
MyApp.csprojand copy it over your ownMyApp.csproj - Take the folder named
Propertiesand copy it over your ownMyApp
- Take the contents of the
If you have your own
PackageReferenceandProjectReference, make sure to preserve them.From the empty app created at step one, take the
Platformsfolder and copy it over your ownMyAppfolder.In you app's
MyApp.csproj, create the following block:<Choose> <When Condition="'$(TargetFramework)'=='net9.0-ios'"> </When> <When Condition="'$(TargetFramework)'=='net9.0-android'"> </When> <When Condition="'$(TargetFramework)'=='net9.0-windows10.0.19041'"> </When> <When Condition="'$(TargetFramework)'=='net9.0-desktop'"> </When> <When Condition="'$(TargetFramework)'=='net9.0-browserwasm'"> </When> </Choose>This will allow us to place custom project configurations in each of those sections. Use the ones that are relevant to your project targets.
From the empty app created at step one, take the
App.xamlandApp.xaml.csand copy those over your ownMyAppfolder.Copy the individual modifications you made to your
AppResources.xamlandApp.csintoApp.xamlandApp.xaml.cs, respectively. Those can, for instance, be changes made toOnLaunched,InitializeLogging, orRegisterRoutes.For the WebAssembly project, most of the configuration is now included by the
Uno.Sdk. You can:- Move all the files from your
MyApp.Wasmfolder to thePlatforms/WebAssemblyfolder, exceptMyApp.Wasm.csprojand thePropertiesfolder. - Copy the individual configurations,
ProjectReferenceandPackageReferenceentries from yourMyApp.Wasm.csprojto yourMyApp.csproj, into the appropriateWhencondition block we created above. This can include properties likeWasmShellGenerateAOTProfileorWasmShellMonoRuntimeExecutionMode, depending on your choices. - Delete the
MyApp.Wasmfolder
- Move all the files from your
For the Mobile project, you can:
- In your app, move the folders
MyApp.Mobile/Android,MyApp.Mobile/iOSto theMyApp/Platforms. - Copy the individual configurations,
ProjectReferenceandPackageReferenceentries from yourMyApp.Mobile.csprojto yourMyApp.csproj, into the appropriateWhencondition block we created above. This can include properties likeApplicationTitleorApplicationId, depending on your choices. - Delete the
MyApp.Mobilefolder
- In your app, move the folders
For the Skia.Gtk, Skia.Wpf and Skia.Framebuffer projects, you can:
- Copy individual modifications made to the
Program.csof each platform over toPlatforms/Desktop/Program.cs - Copy the individual configurations,
ProjectReferenceandPackageReferenceentries from yourMyApp.Skia.[Gtk|Wpf|Framebuffer].csprojto yourMyApp.csproj, into the appropriateWhencondition block we created above. - You can also copy the individual modifications made to
app.manifestandPackage.manifesttoMyApp. Those two files are now shared across platforms. - Delete the
MyApp.Skia.[Gtk|Wpf|Framebuffer]folders
- Copy individual modifications made to the
For the
MyApp.Windowsproject, you can:- Copy the individual configurations,
ProjectReferenceandPackageReferenceentries from yourMyApp.Windows.csprojto yourMyApp.csproj, into the appropriateWhencondition block we created above. - You can copy the individual modifications made to
app.manifestandPackage.manifesttoMyApp. Those two files are now shared across platforms.
- Copy the individual configurations,
For the
MyApp.[Shared|Base]project, you can:- Move the
IconsandSplashfolders to theMyApp/Assets - If you've made modifications to the
base.propsfile, you can copy those over to theMyApp.csproj, outside theChoosesection. - If you've made individual changes to the
AppHead.xamlfile, copy those over to theApp.xamlfile - If you've made individual changes to the
AppHead.xaml.csfile, copy those over to theApp.xaml.csfile - Delete the
MyApp.[Shared|Base]folder
- Move the
In All the
.csfiles, replaceAppHeadwithAppOnce done, you can remove the
Platformsfolder from your solution explorer, as all other platform heads have been deleted.If you have a
MyApp.Serverproject, make sure to change from:<ProjectReference Include="..\MyApp.Wasm\MyApp.Wasm.csproj" />to
<ProjectReference Include="..\MyApp\MyApp.csproj" SetTargetFramework="TargetFramework=net9.0-browserwasm" ReferenceOutputAssembly="false" />From the empty app created at step one, take the
Directory.Build.propsandDirectory.Build.targetsfiles and copy those over your own root folder. Make sure to copy individual changes made in your file, such asCSharpVersionorNullable.From the empty app created at step one, take the
Directory.Packages.propsfile and copy it over to your own root folder. All of the NuGet packages can be removed from this file, as the Uno.SDK provides those automatically.In all the projects files, replace
$(DotnetVersion)withnet9.0Remove the
solution-config.props.samplefile. This part is now handled by Uno Platform automatically.
At this point, your solution can be compiled using a single project and Uno Platform 5.2. For a guide through using the new single project, head over to our getting started.
Wrapping up
Now that your project has gotten simplified, you can head over to our Uno.Sdk documentation to explore its features.