简体   繁体   English

VS Cordova:有什么方法可以根据所选配置来应用不同的config.xml设置?

[英]VS Cordova: is there any way to apply different config.xml settings depending on chosen configuration?

I need to use different app IDs, since was given two provisioning profiles for com.myapp and com.beta.myapp. 我需要使用不同的应用程序ID,因为已为com.myapp和com.beta.myapp提供了两个配置文件。 For now I have to change widget:id in config.xml every time I change the current configuration from Debug to Release and vice versa. 现在,每次将当前配置从Debug更改为Release时,都必须更改config.xml中的widget:id,反之亦然。 Can this be automated? 这可以自动化吗? I know I can tweak .jsproj by implementing a BeforeBuild/BuildDependsOn handler, even using web.config transformations. 我知道我可以通过实现BeforeBuild / BuildDependsOn处理程序来调整.jsproj,甚至可以使用web.config转换。 Is there a simpler, preferably built-in way to do the same thing? 是否有一种更简单的,最好是内置的方法来完成相同的事情?

Note: customizing node.js and/or VS files is not an option, as I prefer modifying files that are part of the project repository to be able to store and distribute the changes along with codebase. 注意:不能自定义node.js和/或VS文件,因为我更喜欢修改项目存储库中的文件,以便能够与代码库一起存储和分发更改。

The issue has been resolved. 该问题已解决。

First off, create the following files in res\\native\\ios\\cordova: 首先,在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>

See Build Settings Reference for complete list of supported settings. 有关支持的设置的完整列表,请参见《 构建设置参考 》。 Note that the BUNDLE_ID is a custom constant that is explained below. 注意, BUNDLE_ID是一个自定义常量,下面将对其进行说明。

If you want to have the files grouped together in Solution Explorer, just edit your .jsproj file as follows: 如果要在“解决方案资源管理器”中将文件分组在一起,只需按如下所示编辑.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>

Finally, edit your config.xml as follows: 最后,如下编辑您的config.xml:

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

This will set the iOS bundle ID to whatever value you assigned in the target .xcconfig. 这会将iOS捆绑包ID设置为您在目标.xcconfig中分配的任何值。

A Cordova hook might be a way to accomplish this. 科尔多瓦钩可能是实现此目的的一种方法。 Here is an article on how Cordova hooks work. 是有关Cordova钩子如何工作的文章。 You might want to have write up a before_prepare hook and update the config.xml before the native platform is prepared and compiled. 您可能需要编写一个before_prepare挂钩并在准备和编译本机平台之前更新config.xml。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM