16

无论如何,我可以在不打开 xcode 的情况下更改 xcode 中的设置吗?我有一个自动化的 xcodebuild / xcrun 进程正在进行,但我需要更改 1 个值:

目标 > 选择您的目标 > 构建设置 > 代码签名资源规则路径添加:$(SDKROOT)/ResourceRules.plist

我找不到任何可以放置此行的文件...

4

3 回答 3

25

你可以做的是运行:

xcodebuild -target <target> -configuration <configuration> -showBuildSettings

此命令显示为目标填充的所有设置和传递的配置。找到包含的密钥的名称$(SDKROOT)/ResourceRules.plist(我们称之为THE_KEY),然后尝试:

xcodebuild -target <target> -configuration <configuration> THE_KEY=<new_value>

不要保证它会起作用。

于 2014-11-28T13:13:23.023 回答
5

你可以试试pbxproj。这是一个 python 模块,可帮助您使用命令行操作 Xcode 项目。

与您的问题相关的部分可能是https://github.com/kronenthaler/mod-pbxproj/wiki/flags#add-code-sign

你可以pip install pbxproj拥有它。

这是官方仓库中提供的示例:

from pbxproj import XcodeProject
# open the project
project = XcodeProject.load('myapp.xcodeproj/project.pbxproj')

# add a file to it, force=false to not add it if it's already in the project
project.add_file('MyClass.swift', force=False)

# set a Other Linker Flags
project.add_other_ldflags('-ObjC')

# save the project, otherwise your changes won't be picked up by Xcode
project.save()
于 2017-03-01T13:36:31.920 回答
0

如果您使用 CocoaPods,您已经安装了 Xcodeproj 作为依赖项:https ://github.com/CocoaPods/Xcodeproj

这是一个打印每个构建配置(调试,发布,...)的更改的示例:

#!/usr/bin/env ruby

require "xcodeproj"

project_path = File.join(File.dirname(__FILE__), 'MultiMarkdown', 'build-xcode', 'libMultiMarkdown.xcodeproj')
project = Xcodeproj::Project.open(project_path)
target = project.targets.select { |t| t.name == "libMultiMarkdown" }.first

new_build_dir = '$SYMROOT/$CONFIGURATION'
outdated_configs = target.build_configurations.select { |c| c.build_settings['CONFIGURATION_BUILD_DIR'] != new_build_dir }

if outdated_configs.empty?
  puts "All up-to-date"
  exit
end

outdated_configs.each do |config|
  old = config.build_settings['CONFIGURATION_BUILD_DIR']
  config.build_settings['CONFIGURATION_BUILD_DIR'] = new_build_dir
  puts "- [#{config.name}]:  Changed `CONFIGURATION_BUILD_DIR` from #{old} to #{new_build_dir}"
end

if project.dirty?
  puts "Saving changes ..."
  project.save
end

您可以将密钥替换为CODE_SIGN_RESOURCE_RULES_PATH并对其进行修改。对于所有目标:

new_path = "path/to/append"
target.build_configurations.each do |config|
  config.build_settings['CODE_SIGN_RESOURCE_RULES_PATH'] += new_path
end

同样,由于这是 CocoaPods 附带的,如果您有需要它的依赖项,您可以在 CocoaPods 挂钩中使用几乎相同的代码。

于 2021-07-02T13:23:03.937 回答