如何两次调用rake目标

3

我通过修改.csproj文件以包含额外的编译符号,从我的.sln生成两个不同的DLL文件集。我正在使用rake来构建解决方案,并拥有以下Build任务:

#==========================================================
desc "Builds the DPSF.sln in Release mode."
msbuild :Build do |msb|
    puts 'Building the DPSF solution...'
    msb.properties :configuration => :Release
    msb.targets [:Clean, :Rebuild]
    msb.solution = DPSF_SOLUTION_FILE_PATH
    msb.parameters "/nologo", "/maxcpucount", "/fileLogger", "/noconsolelogger"
    msb.verbosity = "quiet" # Use "diagnostic" instead of "quiet" for troubleshooting build problems.

    # Delete the build log file if the build was successful (otherwise the script will puke before this point).
    File.delete('msbuild.log')
end

接下来,我尝试使用以下方式生成两组 DLL 文件:

desc "Builds new regular and AsDrawableGameComponent DLLs."
task :BuildNewDLLs => [:DeleteExistingDLLs, :Build, :UpdateCsprojFilesToBuildAsDrawableGameComponentDLLs, :Build, :RevertCsprojFilesToBuildRegularDLLs]

你可以看到我在这里调用了两次 :Build。问题是只有第一个运行。如果我复制/粘贴我的 :Build 目标并将其命名为 :Build2,然后更改 :BuildNewDLLs 调用第二个 :Build2,那么一切都正常工作。所以如何使我能够从 :BuildNewDLLs 目标内多次调用 :Build 目标呢?
提前感谢。
2个回答

7

我知道这是一个老问题,但我刚花了15分钟弄清楚了,所以为了文档的完整性,我在这里分享一下:

你可以从想要重新启用的相同任务中调用 reenable。由于 task 块将当前任务作为第一个参数产生,因此你可以这样做:

task :thing do |t|
  puts "hello"
  t.reenable
end

现在这个可以工作了:

rake thing thing

6
默认情况下,Rake会确保每个rake任务在会话期间执行一次且仅执行一次。您可以使用以下代码重新启用构建任务。
::Rake.application['Build'].reenable

这将允许在同一会话中重新执行它。


我应该把这段代码放在哪里?我尝试了:task :BuildNewDLLs => [:DeleteExistingDLLs, :Build, :UpdateCsprojFilesToBuildAsDrawableGameComponentDLLs, ::Rake.application['Build'].reenable, :Build, :RevertCsprojFilesToBuildRegularDLLs]但是出现了错误“不知道如何构建任务'Build'”。我尝试将其添加到:UpdateCsprojFilesToBuildAsDrawableGameComponentDLLs任务的底部,但是Build仍然没有运行。我还尝试将其放在自己的任务":RenableBuildTask"中,并在第二个:Build之前调用它,但第二次仍然没有运行。我错过了什么吗? - deadlydog
我不确定为什么它在那个点上无法运行。也许添加一个名为“rebuild”的新任务,执行该行,然后通过以下方式手动调用该任务:::Rake.application['Build'].invoke - Daniel Evans
不行,如果我使用:task :ReBuild do ::Rake.application['Build'].reenable ::Rake.application['Build'].invoke end并将 :ReBuild 替换为两个 :Build 目标,它仍然只在第一次构建时进行构建,而不会第二次运行。它只是在执行 :UpdateCsprojFilesToBuildAsDrawableGameComponentDLLs 任务后跳过到 :RevertCsprojFilesToBuildRegularDLLs 任务。还有其他想法吗?非常感谢你迄今为止提供的帮助 :) - deadlydog
尝试将“build”作为第一个任务,“rebuild”作为第二个任务。这只是我的猜测,但我认为rake可能会从依赖数组中删除重复项。 - Daniel Evans
1
是的,先使用 :Build,然后再用 :Rebuild 解决了问题。现在我的脚本中不需要重复的代码了!非常感谢! :) - deadlydog
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接