How to call rake target twice

限于喜欢 提交于 2019-12-10 19:33:39

问题


I generate two different sets of DLL files from my .sln by modifying the .csproj files to include an extra compilation symbol. I'm using rake to build the solution, and have the following Build task:

#==========================================================
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

I then try to generate both sets of DLL files using:

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

You can see that I call :Build twice here. The problem is that only the first one runs. If I copy/paste my :Build target and call it :Build2 and change :BuildNewDLLs to call :Build2 the second time, then everything works fine. So how can I make it so that I can call the :Build target multiple times from within the :BuildNewDLLs target?

Thanks in advance.


回答1:


Rake will, by default, ensure that each rake task is executed once and only once per session. You can re-enable your build task with the following code.

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

That will allow it to be re-executed in the same session.




回答2:


I know this is an old question, but I just spent 15 minutes figuring this out, so for the sake of documentation, here goes:

You can call reenable from within the same task that you wish to reenable. And since the task block yields the current task as first argument, you can do:

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

And now this works:

rake thing thing


来源:https://stackoverflow.com/questions/10391834/how-to-call-rake-target-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!