2012-04-30 40 views
2

我通過修改.csproj文件以包含額外的編譯符號,從我的.sln生成兩組不同的DLL文件。我用耙子來構建解決方案,並具有以下構建任務:如何調用兩次耙目標

#========================================================== 
desc "Builds the DPSF.sln in Release mode." 
msbuild :Build do |msb| 
    puts 'Building the DPSF solution...' 
    msb.properties :configuration => :Release 
    msb.targets [:Clean, :Rebuild] 
    msb.solution = DPSF_SOLUTION_FILE_PATH 
    msb.parameters "/nologo", "/maxcpucount", "/fileLogger", "/noconsolelogger" 
    msb.verbosity = "quiet" # Use "diagnostic" instead of "quiet" for troubleshooting build problems. 

    # Delete the build log file if the build was successful (otherwise the script will puke before this point). 
    File.delete('msbuild.log') 
end 

然後我嘗試使用,以產生兩套DLL文件:

desc "Builds new regular and AsDrawableGameComponent DLLs." 
task :BuildNewDLLs => [:DeleteExistingDLLs, :Build, :UpdateCsprojFilesToBuildAsDrawableGameComponentDLLs, :Build, :RevertCsprojFilesToBuildRegularDLLs] 

你可以看到,我呼籲:在這裏建造兩次。問題是隻有第一個運行。如果我複製/粘貼我的:構建目標並調用它:Build2並更改:BuildNewDLLs第二次調用:Build2,那麼一切正常。那麼,我該如何做到這一點,以便我可以在BuildNewDLLs目標中多次調用:Build目標?

在此先感謝。

回答

6

默認情況下,Rake將確保每個rake任務在每個會話中執行一次且僅執行一次。您可以使用以下代碼重新啓用您的構建任務。

::Rake.application['Build'].reenable 

這將允許它在同一會話中重新執行。

+0

我在哪裏可以把這個代碼?我想: '任務:BuildNewDLLs => [:DeleteExistingDLLs,:構建,:UpdateCsprojFilesToBuildAsDrawableGameComponentDLLs,:: Rake.application [ '生成']重新啓用,:建立,:RevertCsprojFilesToBuildRegularDLLs]' ,其提供了一個錯誤「不要不知道如何構建「構建」任務「。 我試着將它添加到UpdateCsprojFilesToBuildAsDrawableGameComponentDLLs任務的底部,但Build仍然沒有運行。 我試着把它放在它自己的任務「:RenableBuildTask」中,並在第二次構建之前調用它,但它仍然沒有第二次運行。 我錯過了什麼? – deadlydog

+0

我也嘗試將此代碼添加到生成任務本身的底部,但它仍然沒有第二次運行。 – deadlydog

+0

我也試過使用:'Rake :: Task [「Build」]。reenable'建議在[link](http://stackoverflow.com/questions/577944/how-to-run-rake-tasks-from-內部耙 - 任務),但有相同的結果:( – deadlydog

6

我現在k該設計是一個老問題,但我只用了15分鐘搞清楚了這一點,所以對於文檔的緣故,這裏有雲:

您可以從您希望在同一任務中調用reenable重新啓用。而且,由於task塊產生當前的任務,因爲第一個參數,你可以這樣做:

task :thing do |t| 
    puts "hello" 
    t.reenable 
end 

現在這個工程:

rake thing thing