我正在尝试使用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几天前才发布。它默认为.NET 4,并将.path_to_command缩短到.command。但是,由于默认为默认,您无需指定使用的.command。我将在此处使用此语法进行示例。您可以在 http://albacorebuild.net

选项1

将解决方案列表加载到数组中,并为每个解决方案调用MSBUILD。这将通过多个MSBUILD实例附加:构建任务,当您调用以下任务时,所有这些任务都将被构建。

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 作为对另一任务的依赖,您将建立所有解决方案。

...

根据我在此处显示的内容,可能会有十几种变化。但是,它们并没有显着差异 - 只是找到所有解决方案或通过它们循环的几种不同方法。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top