2011-09-27 109 views
4

我一直想弄清楚如何以编程方式将文件添加到Xcode4项目,它似乎像AppleScript将要走的路,但我遇到“缺失值”错误。如何以编程方式将构建文件添加到Xcode4?

下面是我得到了代码:我已经试过被注释掉的行,而不是附加命令以及

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 

,但是,这并不工作,要么(我得到“缺失值“)。

“添加”的错误是:

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的文件中,无需首先选中复选框将其添加到“目标成员”中。

回答

5

我最终把这个问题发送给了xcode开发人员列表上的开发人员,我得到的响应实际上是“你不能”。

+2

有时候,“你不能”表示:“我们不希望你做/知道仙大概,我相信你可以用某种方式来做,但他们会在商店里阻止它。 – mthama

2

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

这个文件是一个GUID汤,但是一旦你看了它一段时间,似乎可以安全地修改它,特别是如果你只是添加东西。

编辑:

发现这个计算器的答案是可能的帮助。

Tutorial or Guide for Scripting XCode Build Phases

+0

是的,我砍掉了MonoDevelop的pbxproj序列化程序,这就是我们所做的,但是如果MonoDevelop稍后想要将更多文件推送到项目中,那么当Xcode已经在打开该项目的情况下运行时,这不是一个好的解决方案。 – jstedfast

0

有可添加一个不良记录用户定义的构建设置。文件既可以排除包括来自编译

转到您的目标的生成设置>点击+按钮>添加用户定义的设置

的关键是要么INCLUDED_SOURCE_FILE_NAMESEXCLUDED_SOURCE_FILE_NAMES

的值是一个空间文件路径分隔列表

见参考文献: http://lists.apple.com/archives/xcode-users/2009/Jun/msg00153.html

相关问题