maui
maui copied to clipboard
Documentation for Multi-Project setup.
Description

In the MAUI GA blog entry, there is a section stating that MAUI supports being used in a "multi-project" (Multiple Projects with single target platforms, as opposed to a "Single-Project" which contains multiple target frameworks). However, I can't set it up. There's no template, nor samples in the MAUI repos for how to pull this off.
I've tried creating my own project (https://github.com/drasticactions/MauiMultiProject) to show this. While I was able to get Android to launch from a MAUI app based in a class project, I've been unable to get the others set up successfully. WinUI will throw an exception that Application.Current is null.

I'm not sure how to set this up properly. Since we say this is a supported usecase, I think there should be documentation (either a sample or a template) with it setup. That will make it easier for anyone to integrate MAUI into a "single" application project.
Steps to Reproduce
Try and run https://github.com/drasticactions/MauiMultiProject on various platforms.
Version with bug
Release Candidate 3 (current)
Last version that worked well
Release Candidate 3 (current)
Affected platforms
iOS, Android, Windows, macOS
Affected platform versions
All
Did you find any workaround?
No response
Relevant log output
No response
+1 on this. Would really appreciate some documentation. It is very difficult to maintain in a single project and most of us migrating from xamarin with an existing CI/CD environment would prefer to achieve the same project structure in MAUI as well.
Although I am able to build and run the given repo sample (with slight changes) successfully for iOS and Droid with .net7, there are still build configuration and plaform related issues especially in iOS.
As soon as I set <UseMaui> flag as true in a net7.0-ios target project, I am unable to create platforms iPhone and iPhoneSimulator under the build configuration. Explicitly setting platforms doesn't work either.
<Platforms>iPhone;iPhoneSimulator;AnyCPU</Platforms>
Shared project containing xaml views:
<TargetFramework>net7.0</TargetFramework>
<UseMaui>true</UseMaui>
<SingleProject>false</SingleProject>
iOS project:
<TargetFramework>net7.0-ios</TargetFramework>
<OutputType>Exe</OutputType>
<UseMaui>true</UseMaui>
<SingleProject>false</SingleProject>
Droid project:
<TargetFramework>net7.0-android</TargetFramework>
<OutputType>Exe</OutputType>
<UseMaui>true</UseMaui>
<SingleProject>false</SingleProject>
+1 This would greatly help the migration story since most xamarin apps are multi project setups.
+1 UP
++ 1 UP Hey @jfversluis Why is there no response on that issue? We want to keep the Xamarin.Forms architecture as Multi-project solution, even after migration to MAUI.
@ericbrunner if that is what you want, you should be able to use the .NET Upgrade Assistant which will help you with both that migration as well as doing that with multiple projects.
+1 UP please document creating multi-project setup for new apps, too, not only migrating old ones
@jfversluis if it would be that easy I would'nt bother you. I tried CLI ugrade-assistant and converted android, ios and the common xamarin project but did't get it working. Now I try the VS Ugrade Tool extension and the latest VS Preview version
I've just tried the repo in the first comment (https://github.com/drasticactions/MauiMultiProject) and without changing anything I was able to run iOS, Android and Mac Catalyst. So you basically want to mimic whatever is in that project.
For Windows there seems to be something not working unfortunately, probably because some configuration is missing or incomplete.
I understand this issue is about documentation for it, I don't think that will come anytime soon. Single-project is our recommended and primary approach at this time. Maybe someone from the community might be able to help out here.
@jfversluis interesting. I have no devices to choose from im visual studio for that (https://github.com/drasticactions/MauiMultiProject).
dispite the fact that one real and on emulator device are avialable (see vysor on left side)
therefore that error message
Interesting. I was on Visual Studio for Mac and it worked without a problem there. On Windows I indeed see the same. Ironically enough, adding <SingleProject>True</SingleProject> to your Android project makes the devices show up.
Then it complains about some resources it can't find in the AndroidManifest.xml. Seems like that happens because the files under Resources aren't set to BuildAction AndroidResource.
SingleProject=True tells the compiler that the root things are shared and it needs to look at Platforms/Android
The IDE not showing devices is a separate bug and should be logged with VS using the feedback tool.
@jfversluis what is the error for windows?
@davidbritch do we have docs for multiple projects? Do we need docs or does/should it just work? Is there any docs with the upgrade assistant maybe?
Then it complains about some resources it can't find in the
AndroidManifest.xml. Seems like that happens because the files underResourcesaren't set to BuildActionAndroidResource.
This is what I meant by
Then it complains about some resources it can't find in the AndroidManifest.xml. Seems like that happens because the files under Resources aren't set to BuildAction AndroidResource.
Remove the references to those files or (probably) set the BuildAction for those files to AndroidResource
@davidbritch do we have docs for multiple projects? Do we need docs or does/should it just work? Is there any docs with the upgrade assistant maybe?
@davidortinau I think this is more upgrade related, I think that was on your plate?
@jfversluis what is the error for windows?
@mattleibow It's hard to capture the details, but I think the key is somewhere here.
It throws an NRE and if you look at the Stack Trace, it just calls the InitializeComponent and goes through XAML stuff, but there is a hint to a RadioButton there (there is no RadioButton in the app...) and some reference to ResolveThemeColor.
My gut tells me there is some initialization somewhere that is missed.
Full call stack: https://gist.github.com/jfversluis/ab3b01d7fb570ec0025a578e5969aa89
If someone interested, here is an original Xamarin.Forms solution and a Migration to a MAUI Single-Project and Multi-Project Solution:
- Xamarin.Forms
OriginalCodebase: https://github.com/ericbrunner/TaskyApp.XamarinForms.git - .NET MAUI Migration as
Single-ProjectCodebase: https://github.com/ericbrunner/TaskyApp.Maui.SingleProject.git - .NET MAUI Migration as
Multi-ProjectCodebase: https://github.com/ericbrunner/TaskyApp.Maui.git => @jfversluis it would be nice when you can take a look on the iOS project in theMulti-Project. When I start the app the iOS screen remains black. Android is working.
Resourcesaren't set to BuildActionAndroidResource.
@jfversluis You comment your own comment. Pretty awesome ;-) Ok, let's get more serious.
I had success with the AndroidResources in a Multi-Project Solution. But it's not fully as you explained.
- The mipmap/icon compiler error could be fixed by right-click on
and set to
AndroidResource. - My Drawable icons where not accessible dispite that I set all Drawable Android images to
AndroidReosurce.
After some investigation I found @mattleibow reported an issue Not easy to add a "AndroidResource" to a maui project and Resource is ambiguous.
So the trick is to fully qualify your Resource in the Android Project, because one is the MAUI Resource and one is the Android Platform Resource. So you end up with to different created Resource.designer.cs.
+1UP
If someone interested, here is an original
Xamarin.Formssolution and a Migration to a MAUISingle-ProjectandMulti-ProjectSolution:
- Xamarin.Forms
OriginalCodebase: https://github.com/ericbrunner/TaskyApp.XamarinForms.git- .NET MAUI Migration as
Single-ProjectCodebase: https://github.com/ericbrunner/TaskyApp.Maui.SingleProject.git- .NET MAUI Migration as
Multi-ProjectCodebase: https://github.com/ericbrunner/TaskyApp.Maui.git => @jfversluis it would be nice when you can take a look on the iOS project in theMulti-Project. When I start the app the iOS screen remains black. Android is working.
Multi-Project is not available through the given link, can you please share it again.
@Alvin-2101 Multi-Project was cancelled on my side due to the Microsoft advice to work with a Single-Project structure
@Alvin-2101 I added a Migration Guide here, maybe helpful.
I also created a multi head maui app project and template some time ago https://github.com/mattleibow/MauiMultiHeadProject
@jfversluis interesting. I have no devices to choose from im visual studio for that (https://github.com/drasticactions/MauiMultiProject). dispite the fact that one real and on emulator device are avialable (see vysor on left side)
therefore that error message
I'm experiencing the same issues. In Visual Studio no devices to select. When pressed Start i always get some Android simulator. Any solutions to this?
@Alvin-2101
Multi-Projectwas cancelled on my side due to the Microsoft advice to work with aSingle-Projectstructure
So does this mean that Microsoft aren't supporting Multi-Project now? I can't find any up to date recommendations or un-recommendations.
I'm looking at upgrading a pretty complex existing application, which I think would be better kept as multi-project. But I don't want to find that I've got problems later on. This is the flagship app for my client, and it would be disastrous to pick the wrong structure and have errors/problems as a result.
I am keeping the multiple structure until the point I can and then I will be moving to a single project structure.
I am keeping the multiple structure until the point I can and then I will be moving to a single project structure.
Thanks -I think I need to take the plunge and go for the probably more complex migration and go straight to single project.
We just tried to migrate to a large Xamarin.Forms app to a multi project solution, we ran into this problem of not being able to deploy.
If Microsoft isn't going to support/fix the multi project solution then they should remove it from the migration guide and make it obvious that you have to go straight to a single project solution.
We just tried to migrate to a large Xamarin.Forms app to a multi project solution, we ran into this problem of not being able to deploy.
If Microsoft isn't going to support/fix the multi project solution then they should remove it from the migration guide and make it obvious that you have to go straight to a single project solution.
Can you elaborate on what exactly is the problem/error that you are facing and for which platform?
therefore that error message 