【问题标题】:VS Cordova: is there any way to apply different config.xml settings depending on chosen configuration?VS Cordova:有没有办法根据选择的配置应用不同的 config.xml 设置?
【发布时间】:2015-03-19 14:58:53
【问题描述】:

我需要使用不同的应用 ID,因为为 com.myapp 和 com.beta.myapp 提供了两个配置文件。现在,每次我将当前配置从 Debug 更改为 Release 时,我都必须更改 config.xml 中的 widget:id,反之亦然。这可以自动化吗?我知道我可以通过实现 BeforeBuild/BuildDependsOn 处理程序来调整 .jsproj,甚至使用 web.config 转换。有没有更简单、最好是内置的方法来做同样的事情?

注意:自定义 node.js 和/或 VS 文件不是一个选项,因为我更喜欢修改项目存储库中的文件,以便能够存储和分发更改以及代码库。

【问题讨论】:

  • 我还没有尝试过使用 Tools for Apache Cordova 项目,但是您是否考虑过使用 [SlowCheetah](visualstudiogallery.msdn.microsoft.com/…) 并在 config.xml 上使用 Transforms?
  • @mharr,我尝试将它安装到 VS 2013 SP4,但它似乎根本不起作用。

标签: ios visual-studio-cordova


【解决方案1】:

问题已解决。

首先,在 res\native\ios\cordova 中创建以下文件:

// build.xcconfig
// The file contains general iOS settings, e.g.
CODE_SIGN_IDENTITY = <your iOS identity>
// build-debug.xcconfig
// The file contains beta specific iOS settings
#include "build.xcconfig"
BUNDLE_ID = com.your.app.beta
PROVISIONING_PROFILE = <profile GUID>
// build-release.xcconfig
// The file contains release specific iOS settings
#include "build.xcconfig"
BUNDLE_ID = com.your.app
PROVISIONING_PROFILE = <profile GUID>

有关受支持设置的完整列表,请参阅 Build Settings Reference。请注意,BUNDLE_ID 是一个自定义常量,如下所述。

如果您想在解决方案资源管理器中将文件组合在一起,只需按如下方式编辑您的 .jsproj 文件:

<Content Include="res\native\ios\cordova\build.xcconfig" />
<Content Include="res\native\ios\cordova\build-debug.xcconfig">
  <DependentUpon>build.xcconfig</DependentUpon>
</Content>
<Content Include="res\native\ios\cordova\build-release.xcconfig">
  <DependentUpon>build.xcconfig</DependentUpon>
</Content>

最后,如下编辑你的 config.xml:

<widget ... id="com.your.app" ios-CFBundleIdentifier="$(BUNDLE_ID)">
    ...
</widget>

这会将 iOS 捆绑包 ID 设置为您在目标 .xcconfig 中分配的任何值。

【讨论】:

    【解决方案2】:

    Cordova 钩子可能是实现此目的的一种方法。 Here 是一篇关于 Cordova 钩子如何工作的文章。您可能希望在准备和编译本机平台之前编写一个 before_prepare 挂钩并更新 config.xml。

    【讨论】:

    猜你喜欢
    • 2019-12-30
    • 2011-07-25
    • 1970-01-01
    • 2019-10-10
    • 1970-01-01
    • 2020-02-11
    • 2017-02-10
    • 2020-09-22
    • 2010-11-29
    相关资源
    最近更新 更多