【问题标题】:How to target a Xamarin PCL application for multiple customers?如何针对多个客户的 Xamarin PCL 应用程序?
【发布时间】:2016-04-26 15:39:59
【问题描述】:

我在 Visual Studio Community 2015 中有一个 Xamarin PCL 解决方案。

我有兴趣为两个不同的客户部署适用于 Android 和 iOS 的相同应用程序。唯一会改变的是启动图像和应用程序图标。

我曾想过在我的 git 存储库中拥有不同的分支,每个分支对应一个客户。但我认为这不是一个合适的解决方案。

另外,我也想过有不同的配置解决方案,例如在 iOS 中:

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

然后更改每个配置的项目属性上的参数。但是如果我改变了具体配置的参数,切换到另一个配置,然后我回到第一个配置的参数,还有第二个配置的参数。

如果我没记错的话,我必须为每个构建指定不同的包名称,否则,Google Play 和 Apple Store 将不会接受我的应用。

在 Xcode 中,这个概念是目标/目标。

在 Visual Studio 2015 中实现我的目标的正确形式是什么?

【问题讨论】:

    标签: visual-studio deployment xamarin portable-class-library targeting


    【解决方案1】:

    很遗憾,Visual Studio 不支持此功能。

    但是还有第三种解决方案。您可以创建另一个项目并将所有(静态)文件添加为项目的链接。有了这个,您不必在配置或分支之间切换,您只需选择项目。

    要将文件添加为链接,您必须右键单击文件夹 -> 添加 -> 现有文件 -> 从原始项目中选择文件 -> 在“添加”上单击箭头并选择“添加为链接”(或有点相似)

    如果您想通过配置来实现,我建议您阅读此question

    【讨论】:

    • 谢谢@Matt。您的建议对我帮助很大!
    【解决方案2】:

    我已经通过以下步骤实现了解决方案:

    1. 在我的 Visual Studio 解决方案中,在 Droid 项目中,我创建了一个文件夹“Customers”,并在该文件夹中创建了两个子文件夹(每个文件夹对应一个客户“CustomerA”和“CustomerB”)
    2. 我已将图像、resx、...文件放入客户文件夹中,我想为每个客户更改这些文件。
    3. 在项目的根结构中,我创建了一个 PowerShell 脚本 (.ps1) 并编写了以下代码:

      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."
      }
      

    它将文件从特定客户文件夹复制到“资源”文件夹项目。

    1. 我已经转到项目的属性:双击“属性”-> 编译事件--> 预构建,我已经设置了这个调用:

      PowerShell -File "$(ProjectDir)GetCustomerResources.ps1" $(ProjectDir) $(SolutionDir) $(SolutionName)

    2. 前面的这些步骤,我在每个平台项目(Android、iOS、...)中都做了。

    3. 然后,我在“Portable”项目中添加了一个“CustomerTarget.txt”文件,其中他的内容是“CustomerA”或“CustomerB”。

    4. 重建解决方案,仅此而已!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-04
      • 2021-04-05
      • 1970-01-01
      相关资源
      最近更新 更多