Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for Multi-Project setup. #7426

Open
drasticactions opened this issue May 23, 2022 · 35 comments
Open

Documentation for Multi-Project setup. #7426

drasticactions opened this issue May 23, 2022 · 35 comments
Labels
area-docs Conceptual docs, API docs, Samples migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert partner Issue or Request from a partner team platform/android 🤖 platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst platform/windows 🪟 Task neither bug nor feature but something that needs to be done in support of either
Milestone

Comments

@drasticactions
Copy link
Contributor

Description

image

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.

image

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

@drasticactions drasticactions added the area-docs Conceptual docs, API docs, Samples label May 23, 2022
@drasticactions drasticactions changed the title Can't create Multi-Project Setup. Documentation for Multi-Project setup. May 23, 2022
@samhouts samhouts added the partner Issue or Request from a partner team label Jul 20, 2022
@mattleibow mattleibow removed their assignment Aug 3, 2022
@mattleibow mattleibow added this to the Backlog milestone Aug 3, 2022
@returnZro
Copy link

+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>

@sam-skedulo
Copy link

+1 This would greatly help the migration story since most xamarin apps are multi project setups.

@Alex-Dobrynin
Copy link
Contributor

+1 UP

@ericbrunner
Copy link

ericbrunner commented Jun 26, 2023

++ 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.

@jfversluis
Copy link
Member

@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.

@Haukinger
Copy link

+1 UP please document creating multi-project setup for new apps, too, not only migrating old ones

@ericbrunner
Copy link

@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

@jfversluis
Copy link
Member

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.

@ericbrunner
Copy link

ericbrunner commented Jun 26, 2023

@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)
image
therefore that error message
image

@jfversluis
Copy link
Member

jfversluis commented Jun 26, 2023

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.

@mattleibow
Copy link
Member

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.

@mattleibow
Copy link
Member

@jfversluis what is the error for windows?

@mattleibow
Copy link
Member

@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?

@jfversluis
Copy link
Member

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.

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

@jfversluis
Copy link
Member

@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
Copy link
Member

jfversluis commented Jun 27, 2023

@jfversluis what is the error for windows?

@mattleibow It's hard to capture the details, but I think the key is somewhere here.

image

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

@ericbrunner
Copy link

ericbrunner commented Jun 27, 2023

If someone interested, here is an original Xamarin.Forms solution and a Migration to a MAUI Single-Project and Multi-Project Solution:

@ericbrunner
Copy link

ericbrunner commented Jun 28, 2023

Resources aren't set to BuildAction AndroidResource.

@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.

  1. The mipmap/icon compiler error could be fixed by right-click on
    image
    and set to AndroidResource.
  2. 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.

image

@yevgeny-sotnikov
Copy link

+1UP

@samhouts samhouts added the Task neither bug nor feature but something that needs to be done in support of either label Jul 31, 2023
@Alvin-2101
Copy link

If someone interested, here is an original Xamarin.Forms solution and a Migration to a MAUI Single-Project and Multi-Project Solution:

Multi-Project is not available through the given link, can you please share it again.

@ericbrunner
Copy link

ericbrunner commented Sep 23, 2023

@Alvin-2101 Multi-Project was cancelled on my side due to the Microsoft advice to work with a Single-Project structure

@ericbrunner
Copy link

@Alvin-2101 I added a Migration Guide here, maybe helpful.

@Alvin-2101
Copy link

@Alvin-2101 I added a Migration Guide here, maybe helpful.

Thanks I will take a look.

@mattleibow
Copy link
Member

I also created a multi head maui app project and template some time ago https://github.com/mattleibow/MauiMultiHeadProject

@Rickvanderwaal
Copy link

Rickvanderwaal commented Sep 25, 2023

@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) image therefore that error message image

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?

@jameslavery
Copy link

@Alvin-2101 Multi-Project was cancelled on my side due to the Microsoft advice to work with a Single-Project structure

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.

@Alvin-2101
Copy link

I am keeping the multiple structure until the point I can and then I will be moving to a single project structure.

@jameslavery
Copy link

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.

@trampster
Copy link

trampster commented Oct 9, 2023

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.

@returnZro
Copy link

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?

@trampster
Copy link

trampster commented Oct 9, 2023

Same as the people above. There is no deploy option. The green play button just says "Start" the drop down doesn't have the options for android Emulators or Android Local Devices. If you do click on "Start" it fails on the deploy stage but with no info about why (not surprising since I couldn't select where to deploy to)

This is the same as reported by people above, and the consensus seems that you have to use single project solution for it to work. There is no sample for multiple project solutions, there is no dotnet new support, there is no Visual studio new project option. And the Microsoft employee who made an example above (but couldn't get it working) deleted it because he was told to only focus on the single project solution.

Our app supports Android and iOS but we have only migrated android so far.

@yevgeny-sotnikov
Copy link

I also created a multi head maui app project and template some time ago https://github.com/mattleibow/MauiMultiHeadProject

Hi @mattleibow, thank you for this template, it's helpful for our migration. But i have a question: how do we need to declare MAUI Handlers at such project structure? Thank you in advance

@returnZro
Copy link

I also created a multi head maui app project and template some time ago https://github.com/mattleibow/MauiMultiHeadProject

Hi @mattleibow, thank you for this template, it's helpful for our migration. But i have a question: how do we need to declare MAUI Handlers at such project structure? Thank you in advance

I don't know if there is any recommended way from MS for this but this is how I register the handlers:

I have MauiProgram.cs in my shared project. The CreateMauiApp function is set to accept MauiAppBuilder as a parameter.

public static MauiApp CreateMauiApp(MauiAppBuilder builder)
{
        builder
            .UseMauiApp<App>();

        return builder.Build();
}

Then in platform projects, in AppDelegate.cs, override the CreateMauiApp function, create a builder, register the iOS specific handler and pass the builder to MauiProgram.CreateMauiApp.

Do the same for Droid in MainApplication.cs

protected override MauiApp CreateMauiApp()
{
        var builder = MauiApp.CreateBuilder();

        // register your platform handlers to builder here

        return MauiProgram.CreateMauiApp(builder);
}

@rachelkang rachelkang added the migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert label Jan 25, 2024
@mattleibow
Copy link
Member

Adding an official template here: #20365

@yevgeny-sotnikov
Copy link

yevgeny-sotnikov commented Sep 20, 2024

@mattleibow One new question - how to build and run only one platform in Muliti-Project structure?

My case is - i have very limited space for Windows environment and I installed only MAUI & WinUI3 SDK. I don't need to install more SDKs cuz I'm going to test only Windows part, but VS is continiosly asking about Android, iOS and Mac SDK and plcks ability to build WinUI3 project only

Issue is only happening on Windows at VisualcStudio, neither VS4Mac nor rider has this issue. Thank you for your answer in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-docs Conceptual docs, API docs, Samples migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert partner Issue or Request from a partner team platform/android 🤖 platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst platform/windows 🪟 Task neither bug nor feature but something that needs to be done in support of either
Projects
None yet
Development

No branches or pull requests