Search code examples
visual-studiodeploymentxamarinportable-class-librarytargeting

How to target a Xamarin PCL application for multiple customers?


I have a Xamarin PCL solution in Visual Studio Community 2015.

I'm interested in deploying the same application for Android and iOS for two different customers. The only thing that it will change would be the splash image and the application icon.

I have thought in having different branches in my git repository, each branch for one customer. But I think that it isn't a suitable solution.

Also, I have thought to have different configuration solutions, for example, in iOS:

Configuration: [Ad-Hoc customer 1] - Platform: iPhone
Configuration: [Ad-Hoc customer 2] - Platform: iPhone

And then change the params on the project properties for each configuration. But if I change the params for specific configuration, switch to an other configuration, and then I come back the first configuration the params, there are the params of the second configuration.

If I'm not wrong, I have to specify different package names for each build, in other case, Google Play and Apple Store won't accept my apps.

In Xcode the concept is target/targeting.

What's the correct form to achieve my objective in Visual Studio 2015?


Solution

  • I have achieved a solution with steps below:

    1. In my Visual Studio Solution, in Droid project, I have created an folder "Customers" and into this folder I have created two child folders (each one for a customer "CustomerA" and "CustomerB")
    2. Into customer folders I have put the images, resx,... files that I would like to change for each customer.
    3. In the root structure of project, I have created a PowerShell script (.ps1) and I have written this code:

      param ([string] $ProjectDir, [string] $SolutionDir, [string] $SolutionName)
      
      Write-Host "ProjectDir --> " $ProjectDir
      Write-Host "SolutionDir -->" $SolutionDir
      Write-Host "SolutionName --> " $SolutionName
      
      $PathCustomerFileName = $SolutionDir + $SolutionName + "\" + $SolutionName + "\CustomerTarget.txt"
      
      Write-Host "PathCustomerFileName --> " $PathCustomerFileName
      
      $ConfigurationName = Get-Content $SolutionDir$SolutionName"\"$SolutionName"\CustomerTarget.txt"
      
      $CorrectCustomerName = "CustomerA","CustomerB" -Contains $ConfigurationName
      
      If ($ConfigurationName.length -gt 0 -And $CorrectCustomerName) {
      
          $Origin = $ProjectDir + "\Customers\" + $ConfigurationName + ""
          $Destination = $ProjectDir + "\Resources"
      
          robocopy $Origin $Destination /S
      
      } else {
          Write-Host "[ERROR] Error copying customer resources. Check ShellScript params and " $PathCustomerFileName " content file."
      }
      

    It copies the files from specific customer folder to "Resources" folder project.

    1. I have gone to properties on project: double click over "Properties" -> Compilation Events --> Pre-build and I have set this call:

      PowerShell -File "$(ProjectDir)GetCustomerResources.ps1" $(ProjectDir) $(SolutionDir) $(SolutionName) enter image description here

    2. This previous steps, I have done them in each platform project (Android, iOS, ...).

    3. Then, I have added in the "Portable" project a "CustomerTarget.txt" file, where his content would be "CustomerA" or "CustomerB".

    4. Rebuild the solution, and that's all!