Stephan
Stephan

Reputation: 143

Is it possible to structure a Xamarin multiplatform app project for different customers?

right now I am maintaining a Xamarin Multiplatform app that only had to satisfy the needs of one customer. My Visual Studio Solution consists of a Core project with ViewModels and resources as well as an iOS and an Android project with the UIs and platform specific code.

I now have to release the same app for a different customer with only slight changes.

So I was wondering, is there any possibility to have another iOS and android application that 'extends' my other projects, so that I can just override the parts that need changes?

I'm asking because I saw web applications that satisfy just exactly that issues by just including another project and than overriding different services for example.

Upvotes: 4

Views: 957

Answers (2)

zpouip
zpouip

Reputation: 787

If these changes also include some logic, then I would also go with creating multiple Build configurations and using if directives. Then in your code you can have something like:

private void ExecuteApiCall()
{

#if COMPANY1
//do something
#elif COMPANY2
//do something else
#else
//do else

}

If it only requires some UI changes, you can also think about having multiple themes and then just assigning one to specific customer: https://medium.com/@milan.gohil/adding-themes-to-your-xamarin-forms-app-3da3032cc3a1

Upvotes: 1

Saamer
Saamer

Reputation: 5109

Yes there are a lot of ways to do that. Here are just two that came to the top of my head.

Method 1: Multiple Build configs (Intermediate level)

One way is to create multiple build configurations, and select what code is to be run depending on which build you are running. Basically to do this, and assuming you are using a Mac, and that all the data your UI uses comes from your ViewModels in your Core project. Then

  1. in you Core project settings, go to Configurations and select Release and Click on Copy, and then type in the client name.VS screenshot of Core code configuration
  2. Then go to Compiler, Select the client configuration, Add a Define Symbol as shown and press OK VS screenshot of Core code compiler settings
  3. Then in your ViewModel, add your Company specific code using the symbol you defined for the client. Depending on your build configuration, Visual Studio tells you which code will be build using darker colors VS screenshot of ViewModel code with client specific code implementation
  4. Then go to Solution properties->Configurations->General->Add three for each customer/client (once for Android (any CPU), one for iPhone and one for iPhone Simulator).Visual Studio Screen Shot of Solution Properties
  5. So it should look like this - Client1, Client1|iPhone, Client1|iPhoneSimulator, Client2, Client2|iPhone, Client2|iPhoneSimulator. Make sure that "Create configurations for all solution items" is not checked.
  6. Then, go to the Configuration Mappings tab, select Client1 & Client2 and make sure the right projects are going to be built depending on the Platform selected. And make sure the right Configuration of each Project is appropriate (Debug vs Release). In our case, only the Viewmodels needed client specific code, so the rest of the projects build correctly. Visual Studio Screen Shot of Config mappings. Press Ok et puis voila!

Method 2: Azure Devops (Expert level)

If you want to do automate the entire process from commit to publish, Scott MacDougall, a developer, presented at a Toronto Xamarin Meetup shared exactly how you can resolve this problem using Azure Devops to manage over 10 apps that were to be released to different iOS & Android accounts. He would just makes the change once, and then once the ticket/issue/item/task was approved by QA, it would go right into each store. It is a lot more complicated and I would have to study it more to explain it to you.

Upvotes: 1

Related Questions