Msbuild 如何使用Albacore一次构建多个项目?

Msbuild 如何使用Albacore一次构建多个项目?,msbuild,rake,albacore,Msbuild,Rake,Albacore,我正在尝试使用rake和albacore构建多个C#项目。感觉上我应该可以不用一个循环来完成这项工作,但我不能完全让它工作。我要做的是: msbuild :selected_test_projects do |msb, args| @teststorun.each do |project| msb.path_to_command = @net40Path msb.properties :configuration => :Release, msb.targe

我正在尝试使用rake和albacore构建多个C#项目。感觉上我应该可以不用一个循环来完成这项工作,但我不能完全让它工作。我要做的是:

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

目前,MSBuild任务中没有直接支持生成多个解决方案。这主要取决于您最喜欢的语法,但它们都涉及某种循环

顺便说一下:albacore v0.2.2几天前刚刚发布。它默认为.NET4,并将.path_to_命令缩短为.command。但是,由于它是默认值,因此不需要指定要使用的.command。我将在这里的示例中使用此语法。您可以在以下位置阅读其他发行说明:

选项#1

将解决方案列表加载到数组中,并为每个解决方案调用msbuild。这将使用msbuild的多个实例追加:build任务,并且在调用: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\u all\u solutions
或添加
:build\u all\u solutions
作为对另一个任务的依赖时,您的所有解决方案都将生成

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

根据我在这里展示的内容,可能有十几种变体可以实现。然而,它们并没有显著的区别——只是找到所有解决方案的几种不同方法,或者循环使用它们