2010-12-09 52 views
6

我想用耙子和長鰭金槍魚建造多個C#項目。感覺就像我應該能夠做到這一點沒有循環,但我不能讓它工作。我要做的是:如何使用Albacore一次構建多個項目?

msbuild :selected_test_projects do |msb, args| 
    @teststorun.each do |project| 
    msb.path_to_command = @net40Path 
    msb.properties :configuration => :Release, 
    msb.targets [ :Test] 
    msb.solution = project 
    msb.build 
    end 
end 

我寧願做一些清潔劑,如本

msbuild :selected_test_projects do |msb, args| 
    msb.path_to_command = @net40Path 
    msb.properties :configuration => :Release, 
    msb.targets [ :Test] 
    msb.solution = @teststorun 
end 

回答

16

在這一點上,有一個在MSBuild任務建立多種解決方案的直接支持。但有幾個選項可用。它主要歸結爲你最喜歡什麼語法,但它們都涉及到某種循環。

順便說一句:albacore v0.2.2剛剛在幾天前發佈。它默認爲.net 4,並將.path_to_command縮短爲.command。既然它是默認的,但是,你不需要指定.command來使用。我將在這裏使用這個語法作爲例子。您可以在http://albacorebuild.net

選項#讀取其他版本註釋1

負載解決方案的列表到一個數組和呼叫的MSBuild每個解決方案。這會將:build任務附加到msbuild的多個實例,並且當你調用:build任務時,所有這些都將被構建。

solutions = ["something.sln", "another.sln", "etc"] 
solutions.each do |solution| 
    #loops through each of your solutions and adds on to the :build task 

    msbuild :build do |msb, args| 
    msb.properties :configuration => :Release, 
    msb.targets [:Test] 
    msb.solution = solution 
    end 
end 

調用rake build或指定:build就像在任何其他的任務將建立所有解決方案的依賴。

選項#2

選項2基本相同剛纔向......除了可以調用MSBuild類,而不是直接的msbuild任務

msb = MSBuild.new 
msb.solution = ... 
msb.properties ... 
#other settings... 

這使你可以創建任何你想要的任務,然後你可以在任何你想要的地方執行你的循環。例如:

task :build_all_solutions do 
    solutions = FileList["solutions/**/*.sln"] 
    solutions.each do |solution| 
    build_solution solution 
    end 
end 

def build_solution(solution) 
    msb = MSBuild.new 
    msb.properties :configuration => :Release, 
    msb.targets [:Test] 
    msb.solution = solution 
    msb.execute # note: ".execute" replaces ".build" in v0.2.x of albacore 
end 

現在,當你調用rake build_all_solutions或你的另一任務添加:build_all_solutions作爲依賴,你的所有的解決方案將建成。

...

有可能有可以做的基礎上,這裏已經證明了我十幾個變化。但是,它們並沒有顯着差異 - 只有幾種不同的方法來查找所有解決方案,或者循環遍歷它們。

相關問題