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

发布于 2024-10-06 17:31:39 字数 590 浏览 1 评论 0原文

我正在尝试使用 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

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, such 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦开始←不甜 2024-10-13 17:31:39

目前,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 作为另一个任务的依赖项时,您的所有解决方案都将被构建。

...

根据我在这里展示的内容,可能有十几种可以完成的变体。但是,它们并没有显着差异 - 只是找到所有解决方案或循环遍历它们的几种不同方法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文