我正在尝试使用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发布于 2010-12-09 10:37:57
在这一点上,MSBuild任务中没有对构建多个solutions.There的直接支持,但是有几个选项可用。这主要归结于你最喜欢哪种语法,但它们都涉及到某种循环。
顺便说一下: 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添加为另一个任务的依赖项时,将构建所有解决方案。
..。
根据我在这里展示的内容,可能有十几种变体可以完成。然而,它们并没有显著的不同-只是找到所有解决方案的几种不同的方法,或者遍历它们。
https://stackoverflow.com/questions/4393848
复制相似问题