在這一點上,有一個在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
作爲依賴,你的所有的解決方案將建成。
...
有可能有可以做的基礎上,這裏已經證明了我十幾個變化。但是,它們並沒有顯着差異 - 只有幾種不同的方法來查找所有解決方案,或者循環遍歷它們。