是否有可能生成过程中动态地指定包的名字吗? [英] Is it possible to specify package name dynamically during build?
本文介绍了是否有可能生成过程中动态地指定包的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想同时部署调试和发布版本到我的设备在同一时间。我能做到这一点,如果我手动更改包名称清单之前,我建,如变更
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. change
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.package">
到
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.packageDEBUG">
不过,我想自动执行此操作时,我构建解决方案。如果我做了调试版本,它会在清单建立与包=my.packageDEBUG
。
这是可能的,如果是这样,怎么样?
Is this possible, and if so, how?
推荐答案
您需要创建一个自定义的pre-构建事件为您的项目。
You'll need to create a custom Pre-Build Event for your project.
你的项目右键单击并选择属性...
Right-click on your project and select Properties...
然后点击生成事件,这增加了pre-build事件文本框:
Then click on Build Events and add this to the Pre-build event textbox:
PowerShell -File "$(SolutionDir)Update-PackageName.ps1" $(ProjectDir) $(ConfigurationName)
复制下面的PowerShell脚本和解决方案中的文件夹中保存它的更新 - 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"
}
祝你好运!
这篇关于是否有可能生成过程中动态地指定包的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文