我强烈建议您使用持续集成。
我们使用TeamCity for CI,Rake和Albacore的组合来自动化构建。
TeamCity将从您的源代码存储库中检出代码,然后根据需要使用Rake构建应用程序,执行单元测试,甚至运行数据库脚本。成功构建后,您可以将源代码打包为zip文件,或将其复制到您选择的目标位置。
尽管TeamCity可与所有源代码控制系统一起使用,但我们使用Git。
如果不编辑XML文件,使用TeamCity和Rake类似于使用CruiseControl和NANT。当然,如果愿意,您可以将TeamCity与NANT一起使用。
从rakefile.rb中提取的简短示例,该示例执行构建。恕我直言,比XML文件更易于阅读和调试。
require 'albacore'
require 'rexml/document'
require 'find'
VERSION_NO = "1.0"
OUTPUT_PATH = "output"
WEBOUTPUT_PATH = "output/web"
ADMINOUTPUT_PATH = "output/admin"
CONFIG = "Release"
WEB_PATH = "app/Company.Website.Web"
ADMIN_PATH = "app/Company.Website.Admin"
PACKAGE_PATH = "build/package"
DB_SCRIPT_PATH = "Company.Website.DB"
SOLUTION = "Company.Website.sln"
ARTIFACTS_PATH = "d:/build/artifacts/"
DEPLOY_WEB_PATH = "d:/deploy/company/website/"
DEPLOY_ADMIN_PATH = "d:/deploy/company/admin/"
task :default => ['setuptest','assemblyinfo','config','msbuild','createdb','sqlcmd','deploy']
task :setuptest do |setup|
if ENV['BuildNumber'].nil? then ENV['BuildNumber'] = "000" end
VERSION_NO = VERSION_NO + '.' + ENV['BuildNumber']
puts 'Version Number : ' + VERSION_NO
ZIPFILE_WEB = 'Company.Website.Web.' + VERSION_NO
ZIPFILE_ADMIN = 'Company.Website.Admin.' + VERSION_NO
DB_SERVER = "WEB2"
DB_DATABASE = "Website"
CREATEDB_SCRIPT = "app/Company.Website.DB/00CreateDatabaseTEST.sql"
end
assemblyinfotask do |asm|
asm.version = VERSION_NO
asm.company_name = "Company Name"
asm.copyright = "Copyright 2010"
asm.output_file = "CommonAssemblyInfo.cs"
end
task :config do
FileUtils.cp 'NHibernate.test.config', 'NHibernate.config'
end
msbuildtask do |msb|
msb.properties = { :configuration => :Debug }
msb.targets [:Clean, :Build]
msb.solution = "Company.Website.sln"
end
sqlcmdtask :createdb do |sql|
puts "executing sql scripts..."
sql.log_level = :verbose
sql.path_to_command = "sqlcmd.exe"
sql.server = DB_SERVER
sql.database = "master"
sql.scripts << CREATEDB_SCRIPT
end
sqlcmdtask do |sql|
puts "executing sql scripts..."
sql.log_level = :verbose
sql.path_to_command = "sqlcmd.exe"
sql.server = DB_SERVER
sql.database = DB_DATABASE
sql.scripts << "app/Company.Website.DB/01CreateTables.sql"
sql.scripts << "app/Company.Website.DB/02InsertReferenceData.sql"
end
task :deployprep do
FileUtils.remove_dir 'app/Company.Website.Web/obj'
FileUtils.remove_dir 'app/Company.Website.Admin/obj'
end
ziptask :zipweb do |zip|
puts "creating zip package in " + ZIPFILE_WEB
zip.directories_to_zip = ["app/Company.Website.Web"]
zip.output_file = ZIPFILE_WEB + '.zip'
zip.output_path = File.dirname(__FILE__)
end
ziptask :zipadmin do |zip|
puts "creating zip package in " + ZIPFILE_ADMIN
zip.directories_to_zip = ["app/Company.Website.Admin"]
zip.output_file = ZIPFILE_ADMIN + '.zip'
zip.output_path = File.dirname(__FILE__)
end
Albacore是专门为部署.NET应用程序而构建的Rake任务套件。