首页 > 解决方案 > 从 xcodeproj 文件中删除构建配置和方案的脚本?

问题描述

有没有办法通过脚本/命令行从 xcodeproj 中删除构建配置和方案,而无需在文本编辑器中编辑(project.pbxproj),希望它不会交叉验证并影响构建。

我尝试xcodeproj了让您读取 prj 并将其表示为 yaml 的方法,我想要一个可以编辑 yaml 并从中生成 xcodeproj 的工具。

我也尝试删除方案形式xcshareddata仍然没有性能改进。

shell> xcodebuild -project myproject.xcodeproj -list

# output
Information about project "myproject":
    Targets:
        myproject
        myprojectTests
        ScreensForManPages
        UITestsCA
        ....
        ....
        UITestsUS

    Build Configurations:
        ae-debug
        ae-debug-another-condition
        ae-release
        ae-release-another-condition
        ...
        ...
        250+ build config in between
        ...
        ...
        zw-debug
        zw-debug-another-condition
        zw-release
        zw-release-another-condition

    If no build configuration is specified and -scheme is not passed then "ae-release-another-condition" is used.

    Schemes:
        myproject-ae-debug
        myproject-ae-debug-another-condition
        myproject-ae-release
        ...
        ...
        250+ schemes in between
        ...
        ...
        myproject-zw-debug
        myproject-zw-debug-another-condition
        myproject-zw-release
        myproject-zw-release-another-condition

原因:

我最近继承了一个项目,其中有 250 多个构建配置和 250 多个方案。不幸的是,我的工作机器是旧的 mbp,带有运行 osx mojave 和 xcode 10 的 hdd 无法打开项目。(.xcodeproj 文件大约 10mb)

我可以打开项目,但每次点击彩虹轮,列出目标需要 10 多分钟,而且我不知道 xcode 中的选项可以一次删除多个配置/方案。

PS:

Apple 脚本解决方案 没有帮助 xcode 无法及时响应

标签: iosxcodemacoscommand-line

解决方案


在你开始之前

  • Xcode需要完全关闭
  • 如果您要手动编辑您的Xcode项目,请务必 在尝试此操作之前进行备份!

计划

删除您不想要的方案文件:

/MyApp/MyApp.xcodeproj/xcshareddata/xcschemes

编辑管理 plist

/MyApp/MyApp.xcodeproj/xcuserdata/Username.xcuserdatad/xcschemes/xcschememanagement.plist

在文件中删除您不想要的方案(例如。MyApp Custom):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>SchemeUserState</key>
    <dict>
        ///////////////////////////////////////////////// remove start
        <key>MyApp Custom.xcscheme_^#shared#^_</key>
        <dict>
            <key>orderHint</key>
            <integer>1</integer>
        </dict>
        ///////////////////////////////////////////////// remove end
        <key>MyApp.xcscheme_^#shared#^_</key>
        <dict>
            <key>orderHint</key>
            <integer>0</integer>
        </dict>
    </dict>
    <key>SuppressBuildableAutocreation</key>
    <dict>
        <key>AFDACD5A2209867B00004213</key>
        <dict>
            <key>primary</key>
            <true/>
        </dict>
    </dict>
</dict>
</plist>

构建配置

/MyApp/SomeProgram.xcodeproj/project.pbxproj

我不建议手动编辑此文件,而是通过 删除构建配置Xcode,但是如果您在文件中勇敢,您会看到配置。您还可以使用 plist 编辑器(plistbuddy 等)编辑此文件 - 删除您不想要的文件:

AFADF25C22269ABE000D354D =         {
            buildSettings =             {
     ...
         };
     isa = XCBuildConfiguration;
     name = Custom;
};

您还将看到相应的UID与其他配置分组:

AFDACD542209865600004213 =         {
            buildConfigurations =             (
                AFDACD552209865600004213,
                AFDACD562209865600004213,
                AFADF25C22269ABE000D354D ////// remove
            );
            defaultConfigurationIsVisible = 0;
            defaultConfigurationName = Release;
            isa = XCConfigurationList;
        };

现在,当您打开您.xcodeproj的更改时,应该会反映出来。


推荐阅读