如何以编程方式将生成文件添加到Xcode4?

如何以编程方式将生成文件添加到Xcode4?,xcode4,applescript,Xcode4,Applescript,我一直在试图找出如何以编程方式将文件添加到Xcode4项目中,而AppleScript似乎是一个不错的选择,但是我遇到了“缺少值”的错误 以下是我得到的代码: tell application "Xcode" set theProject to first project set theTarget to first target of theProject set theBuildPhase to compile sources phase of theTarget

我一直在试图找出如何以编程方式将文件添加到Xcode4项目中,而AppleScript似乎是一个不错的选择,但是我遇到了“缺少值”的错误

以下是我得到的代码:

tell application "Xcode"
    set theProject to first project
    set theTarget to first target of theProject
    set theBuildPhase to compile sources phase of theTarget
    tell first group of theProject
        set theFileRef to make new file reference with properties {full path:"/Users/jeff/Projects/XcodeTest/XcodeTest/MyViewController.h", name:"MyViewController.h", path:"XcodeTest/MyViewController.h", path type:group relative}
        add theFileRef to theProject
    end tell
    --tell theBuildPhase to make new build file with properties {build phase:theBuildPhase, name:"MyViewController.h", file reference:theFileRef, target:theTarget, project:theProject}
end tell
我也尝试了注释掉的行而不是add命令,但这也不起作用(我得到了“缺少值”)

“添加”错误为:

error "Xcode got an error: file reference id \"251AD3431432472E006E300F\" of Xcode 3 group id \"251AD32C14324645006E300F\" of project \"XcodeTest\" of workspace document \"XcodeTest.xcodeproj/project.xcworkspace\" doesn’t understand the add message." number -1708 from file reference id "251AD3431432472E006E300F" of Xcode 3 group id "251AD32C14324645006E300F" of project "XcodeTest" of workspace document "XcodeTest.xcodeproj/project.xcworkspace"

“创建新引用”确实会将该文件添加到Xcode中的文件列表中,但我还需要将其添加到项目目标中,以便我可以从Xcode向该文件添加操作和出口,而不必首先选中复选框将其添加到“目标成员资格”.

最后,我将这个问题发送给了xcode开发者列表中的开发者,得到的回答实际上是“你不能”。

这在xcode 4中似乎完全被打破了,但我看到了一个这样做的项目。我认为他们正在做的是直接解析和修改“project.pbxproj”文件。(此文件隐藏在xcodeproj捆绑包中)

该文件是一个GUID文件,但一旦您查看它一段时间,似乎就可以安全地修改它,尤其是在您只添加内容的情况下

编辑:

找到这个可能有用的答案


用户定义的生成设置文档不完整,可以添加。可以从编译中排除和包含文件

转到目标的构建设置>点击+按钮>添加用户定义的设置

键是
包含的源文件名
排除的源文件名

该值是以空格分隔的文件路径列表

见参考资料:

是的,我入侵了MonoDevelop的pbxproj序列化程序,我们就是这么做的,但是如果MonoDevelop想在以后将更多文件推送到项目中,当Xcode已经在运行且该项目处于打开状态时,这不是一个好的解决方案。有时,“你不能”意味着“我们不想让你知道。诚恳地说,我相信你能以某种方式做到这一点,但他们会在商店里阻止它。