6

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
4

1 に答える 1

16

現時点では、複数のソリューションを構築するためのMSBuildタスクを直接サポートしていません。ただし、いくつかのオプションを利用できます。これを行うには、ほとんどの場合、どの構文が最適かということになりますが、それらはすべて、ある種のループを伴います。

ちなみに、albacorev0.2.2は数日前にリリースされたばかりです。デフォルトは.net4で、.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

..。

ここで示した内容に基づいて、実行できるバリエーションはおそらく12あります。ただし、それらは大きく異なるわけではありません。すべてのソリューションを見つける、またはそれらをループするためのいくつかの異なる方法です。

于 2010-12-09T02:37:57.273 に答える