How do I build multiple projects at once using Albacore?
I am trying to build multiple C# projects using rake and albacore. It feels like I should be able to do this without a loop, but I can't quite make it work. What I have to do is this:
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
I'd rather do something cleaner, s开发者_运维问答uch as this
msbuild :selected_test_projects do |msb, args|
msb.path_to_command = @net40Path
msb.properties :configuration => :Release,
msb.targets [ :Test]
msb.solution = @teststorun
end
At this point, there's no direct support in the MSBuild task for building multiple solutions.There are a few options available, though. It mostly comes down to what syntax you like the best for doing this, but they all involve a loop of some sort.
By the way: albacore v0.2.2 was just release a few days ago. It defaults to .net 4, and shortens the .path_to_command down to .command. Since it defaults, though, you don't need to specify the .command to use. I'll use this syntax for the examples, here. You can read additional release notes at http://albacorebuild.net
Option #1
Load the list of solutions into an array and call msbuild for each solution. this will append the :build task with multiple instances of msbuild and when you call the :build task, all of them will be built.
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
calling rake build
or specifying :build
as a dependency in any other task will build all of your solutions.
Option #2
option 2 is basically the same what I just showed... except you can call the MSBuild
class directly instead of the msbuild
task
msb = MSBuild.new
msb.solution = ...
msb.properties ...
#other settings...
this let's you create a task any way you wish, and then you can perform your loop wherever you want. For example:
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
Now, when you call rake build_all_solutions
or you add :build_all_solutions
as a dependency on another task, all of your solutions will be built.
...
there are probably have a dozen variations that can be done, based on what I've shown here. However, they don't differ significantly - just a few different ways to find all the solutions, or loop through them.
精彩评论