我们正在将构建环境从NAnt迁移到Rake。一些NAnt任务必须重写。在本例中为XmlPoke task ( NAntContrib库的一部分)。使用Ruby可以很容易地做到这一点。
发布于 2013-03-16 01:38:36
我将回答我以为您在问的问题:如何更新程序集版本号。但我从您的回答中看出,您对一般的XML更新( XML poke任务的副本)很感兴趣。
如何使用Ruby/Rake/Albacore更新程序集版本?
我对.NET项目的建议是始终更新assembly info file中的版本。而不是直接编辑csproj。Albacore包含了这样做的方法,使用AssemblyInfo Task。
如何重新创建NAnt xmlpoke任务?
实际上,我以Albacore的自定义任务的风格编写了几个特定于.NET的file update tasks。我称它们为apprc (用于重写CLI资源文件,它有愚蠢的编码问题)。和appconfig,它可以在任何XML文件上工作。
信息在自述文件中,但它的工作方式与xmlpoke任务略有不同。
appconfig :taskname do |x|
x.files = FileList['relative/wildcard/path/to/*.exe.config']
x.replacements = {
'some/x/path/expression' => 'replacment-value',
'another/x/path/expression' => 'another-replacment!'
}
end发布于 2013-03-08 17:48:43
require 'albacore/tasks/versionizer'
require 'semver'
require 'rexml/document'
include REXML
Albacore::Tasks::Versionizer.new(:versioning)
ver = SemVer.find
ASSEMBLY_VERSION = "#{ SemVer.new(ver.major, ver.minor, ver.patch).format "%M.%m.%p"}" + ".0"
class XmlPoke
attr_accessor :xml_file_path
def initialize xmlfilepath
@xml_file_path = xmlfilepath
end
def pokeelement xpath, value
file = File.open(xml_file_path, 'r')
xmldoc = Document.new(file)
xpathnode = XPath.first(xmldoc, xpath)
xpathnode.text = value
formatter = REXML::Formatters::Default.new
File.open(xml_file_path, 'w') do |result|
formatter.write(xmldoc, result)
end
end
end
desc "Sets Application Version in project file"
task :outlookproj do
projectfilepath = "dotnet_project_path/dotnet_project_name.csproj"
xpath = "/Project/PropertyGroup/ApplicationVersion"
value = "#{ASSEMBLY_VERSION}"
poker = XmlPoke.new projectfilepath
poker.pokeelement xpath, value
endhttps://stackoverflow.com/questions/15291033
复制相似问题