2011-09-27 99 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

相關問題