3

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.

deadlydog
  • 22,611
  • 14
  • 112
  • 118

2 Answers2

7

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
Ifligus
  • 158
  • 3
  • 10
troelskn
  • 115,121
  • 27
  • 131
  • 155
6

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.

Daniel Evans
  • 6,788
  • 1
  • 31
  • 39
  • Where do I put this code? I tried: `task :BuildNewDLLs => [:DeleteExistingDLLs, :Build, :UpdateCsprojFilesToBuildAsDrawableGameComponentDLLs, ::Rake.application['Build'].reenable, :Build, :RevertCsprojFilesToBuildRegularDLLs]` which gives an error "Don't know how to build task 'Build'". I tried adding it to the bottom of the :UpdateCsprojFilesToBuildAsDrawableGameComponentDLLs task, but Build still did not run. And I tried putting it in it's own task ":RenableBuildTask" and called that before the 2nd :Build, but it still did not run the second time. What am I missing? – deadlydog May 01 '12 at 01:54
  • I also tried adding this code to the bottom of the :Build task itself, but it still did not run the second time. – deadlydog May 01 '12 at 02:00
  • I also tried using: `Rake::Task["Build"].reenable` as suggested at [link](http://stackoverflow.com/questions/577944/how-to-run-rake-tasks-from-within-rake-tasks), but had the same results :( – deadlydog May 01 '12 at 02:11
  • I'm not sure why it won't run at that point. Perhaps add a new task called "rebuild" which does that line, then manually calls the task by saying: `::Rake.application['Build'].invoke` – Daniel Evans May 01 '12 at 05:09
  • Nope, if I use: `task :ReBuild do ::Rake.application['Build'].reenable ::Rake.application['Build'].invoke end` and substitute :ReBuild in for both of the :Build targets, it still only does the build the first time and doesn't run it the second time. It just skips to the :RevertCsprojFilesToBuildRegularDLLs task after doing the :UpdateCsprojFilesToBuildAsDrawableGameComponentDLLs tasks. Any other ideas? And thanks for the help so far :) – deadlydog May 01 '12 at 15:47
  • Try having "build" be the first task and "rebuild" being the second. I'm only guessing here, but I would think that rake might remove duplicates from the dependency array. – Daniel Evans May 01 '12 at 15:59
  • 1
    Yup, using :Build first and then :Rebuild second solved the problem. Now I don't need to have duplicate code in my scripts! Thanks so much! :) – deadlydog May 01 '12 at 18:12