【问题标题】:How to call rake target twice如何两次调用 rake 目标
【发布时间】:2023-03-30 03:09:01
【问题描述】:

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

#==========================================================
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 目标呢?

提前致谢。

【问题讨论】:

    标签: ruby build msbuild rake target


    【解决方案1】:

    我知道这是一个老问题,但我只花了 15 分钟来解决这个问题,所以为了记录,这里是:

    您可以在您希望重新启用的同一任务中调用reenable。由于task 块将当前任务作为第一个参数,您可以这样做:

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

    现在可以了:

    rake thing thing
    

    【讨论】:

      【解决方案2】:

      默认情况下,Rake 将确保每个 rake 任务执行一次,并且每个会话仅执行一次。您可以使用以下代码重新启用构建任务。

      ::Rake.application['Build'].reenable
      

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

      【讨论】:

      • 我把这段代码放在哪里?我试过:task :BuildNewDLLs => [:DeleteExistingDLLs, :Build, :UpdateCsprojFilesToBuildAsDrawableGameComponentDLLs, ::Rake.application['Build'].reenable, :Build, :RevertCsprojFilesToBuildRegularDLLs] 给出错误“不知道如何构建任务'构建'”。我尝试将其添加到 :UpdateCsprojFilesToBuildAsDrawableGameComponentDLLs 任务的底部,但 Build 仍然没有运行。我尝试将它放在它自己的任务“:RenableBuildTask”中并在第二次之前调用它:Build,但它仍然没有第二次运行。我错过了什么?
      • 我也尝试将此代码添加到 :Build 任务本身的底部,但它仍然没有运行第二次。
      • 我也尝试使用:Rake::Task["Build"].reenable,正如link 所建议的那样,但结果相同:(
      • 我不知道为什么它不会在那个时候运行。也许添加一个名为“rebuild”的新任务来执行该行,然后手动调用该任务:::Rake.application['Build'].invoke
      • 是的,首先使用 :Build 然后 :Rebuild 第二解决了这个问题。现在我不需要在我的脚本中有重复的代码了!非常感谢! :)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-20
      • 2018-02-25
      • 1970-01-01
      相关资源
      最近更新 更多