更改特定目标 Fastlane 的版本和内部版本号

Changing version and build number for a specific target Fastlane

我正在尝试将 Fastlane 实施到一个包含 30 多个应用程序的 Xcode 项目中。

此刻我被困在为“AppStore”构建应用程序的通道上,因为它必须更改特定目标的版本和内部版本号。我车道的代码是:

desc "Archives and creates the app for the AppStore"
lane :build_appstore do |options|
    scheme = options[:scheme]
    output_directory = options[:output_directory]
    configuration = options[:configuration]
    export_method = options[:export_method]

    bundle_id = options[:bundle_id]
    version = options[:version]
    build = options[:build]

    # Used for increment_version_number. Does it work?
    ENV["APP_IDENTIFIER"] = options[:bundle_id]
      
    increment_version_number(
        version_number: version
    )
    increment_build_number(
        build_number: build
    )
      
    gym(
        scheme: scheme,
        output_directory: output_directory,
        configuration: configuration,
        export_method: export_method
    )
end

车道正常,但当我查看项目时,我发现所有目标的版本和内部版本号都发生了变化,这有点不方便。

有什么想法吗??

我最终使用 xcodeproj ruby 创建并创建了以下通道:

# Sets the "VERSION" and "BUILD" number for a target
#
# @param args [Hash] Key value arguments. All the values are Strings. List: 
#   - target_name: The name of the target (REQUIRED)
#   - version: The version number to be used (REQUIRED)
#   - build: The build number to be used (REQUIRED)
#
desc "Sets the \"VERSION\" and \"BUILD\" number for a target"
lane :set_version_build_number do |args|
    puts("\"set_version_build_number\" lane with ARGUMENTS: #{args}")

    target_name = args[:target_name]
    version = args[:version]
    build = args[:build]

    raise(StandardError, "Invalid ARGUMENTS for: \"set_version_build_number\" LANE") unless (
        target_name != nil &&
        version != nil &&
        build != nil
    )

    puts("Variables:")
    puts("\ttarget_name: #{target_name}")
    puts("\tversion: #{version}")
    puts("\tbuild: #{build}")
    
    project_url = find_xcode_project()
    raise(StandardError, "Invalid Xcode project for: \"set_version_build_number\" LANE") unless project_url != nil
    project = Xcodeproj::Project.open(project_url)

    xc_target = project.targets.find { |target| target.name == target_name }
    raise(StandardError, "Invalid target for: \"set_version_build_number\" LANE") unless xc_target != nil

    xc_target.build_configurations.each { |build_configuration| 
        build_configuration.build_settings["MARKETING_VERSION"] = version
        build_configuration.build_settings["CURRENT_PROJECT_VERSION"] = build
    }

    project.save()
end