我如何让 :default Rake 任务依赖于带参数的任务? [英] How do I have the :default Rake task depend on a task with arguments?

查看:25
本文介绍了我如何让 :default Rake 任务依赖于带参数的任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在玩 Rake 和 Albacore,看看我是否可以替换我们现有的 MSBuild 脚本,该脚本使用非 XML 的东西部署软件.我有一个任务,将 web.config 中的调试值更改为 false.该任务将 web.config 的目录作为参数,但我无法弄清楚在默认任务中提供此参数所需的语法.

I have been playing around with Rake and Albacore, to see if I can replace our existing MSBuild script that deploys software with something that isn't XML. I have a task that will change the debug value inside a web.config to false. The task takes the directory of the web.config as an argument, but I can't quite figure out the syntax needed to supply this argument in the default task.

require 'albacore'
require 'nokogiri'

deployment_path = 'c:/test-mars-deploy'

task :default => [ :build, :publish, :update_web_config['c:/test-mars-deploy'] ]

task :update_web_config, :deploy_path do |t, args|  
  deployment_path = #{args[:deploy_path]}
  web_config_path = File.join deployment_path, 'Web.config'

  File.open(web_config_path, 'r+') do |f|
    doc = Nokogiri::XML(f)
    puts 'finding attribute'
    attribute = doc.xpath('/configuration/system.web/compilation')
    attribute.attr('debug', 'false')
    puts attribute.to_xml
  end

  File.delete(web_config_path)

  File.new(web_config_path, 'w') do |f|
    f.write(doc.to_s)
  end
end

推荐答案

我认为你可能不得不使用旧样式的参数传递,例如:

I think you might have to use the old style parameter passing, eg:

nicholas@hal:/tmp$ cat Rakefile
task :default => :all

deploy_path = ENV['deploy_path'] || "c:/some_path"

task :all do |t, args|
    puts deploy_path.inspect
end

并调用:

nicholas@hal:/tmp$ rake
(in /tmp)
"c:/some_path"

或者,覆盖路径:

nicholas@hal:/tmp$ rake deploy_path=c:/other_path
(in /tmp)
"c:/other_path"

这篇关于我如何让 :default Rake 任务依赖于带参数的任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆