How to call rake target twice

2019-07-01 20:22发布

问题:

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