Is it possible to specify package name dynamically during build?

后端 未结 2 1765
没有蜡笔的小新
没有蜡笔的小新 2020-12-28 11:11

I\'d like to deploy both Debug and Release builds to my device at the same time. I can do this if I manually change the package name in the manifest before I build, e.g. cha

相关标签:
2条回答
  • 2020-12-28 12:09

    You'll need to create a custom Pre-Build Event for your project.

    Right-click on your project and select Properties...

    Then click on Build Events and add this to the Pre-build event textbox:

    PowerShell -File "$(SolutionDir)Update-PackageName.ps1" $(ProjectDir) $(ConfigurationName)
    

    Copy the following PowerShell script and save it in your solution folder as Update-PackageName.ps1

    param ([string] $ProjectDir, [string] $ConfigurationName)
    Write-Host "ProjectDir: $ProjectDir"
    Write-Host "ConfigurationName: $ConfigurationName"
    
    $ManifestPath = $ProjectDir + "Properties\AndroidManifest.xml"
    
    Write-Host "ManifestPath: $ManifestPath"
    
    [xml] $xdoc = Get-Content $ManifestPath
    
    $package = $xdoc.manifest.package
    
    If ($ConfigurationName -eq "Release" -and $package.EndsWith("DEBUG")) 
    { 
        $package = $package.Replace("DEBUG", "") 
    }
    If ($ConfigurationName -eq "Debug" -and -not $package.EndsWith("DEBUG")) 
    { 
        $package = $package + "DEBUG" 
    }
    
    If ($package -ne $xdoc.manifest.package) 
    {
        $xdoc.manifest.package = $package
        $xdoc.Save($ManifestPath)
        Write-Host "AndroidManifest.xml package name updated to $package"
    }
    

    Good luck!

    0 讨论(0)
  • 2020-12-28 12:10

    According to this question on Xamarin's forum you can change the Packaging Properties and specify different AndroidManifest.xml files for each build.

    In the droid.csproj file add the <AndroidManifest> tag like so, for each build configuration:

      <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
        ...
        <AndroidManifest>Properties\AndroidManifestDbg.xml</AndroidManifest>
        ...
    

    Here's the Xamarin's documentation on it.

    0 讨论(0)
提交回复
热议问题