延續上一篇的範例,這次加入版本編號的控制,也就是在建置過程中自動產生 AssemblyInfo.cs 檔案。
下圖是 RakeDemo.sln 的結構,此 solution 包含兩個專案:ConsoleApp1.csproj 和 MyLib.csproj。Rakefile.rb 是跟 solution 檔案放在同一個目錄下。
假設我想要在進行 release build 時,讓 ConsoleApp1.exe 和 MyLib.dll 的組件版本編號一致,我的 rakefile 可以這樣寫:
下圖為 rakefile.rb 的解說:
在產生 AssemblyInfo.cs 時,我刻意在 product_name 屬性中使用中文字,看看能否正確處理中文字元或 Unicode 字元。建置完成後,利用檔案總管查看新產生的 ConsoleApp1.exe 的內容,結果如下圖:
圖中的「產品名稱」應該是 "Rake 範例",可是中文字變成亂碼了。試過將 rakefile.rb 以 ANSI 、UTF-8、Unicode 的字元編碼方式儲存,結果都不行。有的編碼甚至在 IronRuby 解譯檔案時就會顯示錯誤。這似乎是 IronRuby 本身的問題。
不能正確處理中文,這就得扣分了。還是等它可以正確處理中文或 Unicode 字元之後,再來試組態檔轉換的功能吧。
下圖是 RakeDemo.sln 的結構,此 solution 包含兩個專案:ConsoleApp1.csproj 和 MyLib.csproj。Rakefile.rb 是跟 solution 檔案放在同一個目錄下。
假設我想要在進行 release build 時,讓 ConsoleApp1.exe 和 MyLib.dll 的組件版本編號一致,我的 rakefile 可以這樣寫:
require 'albacore'
@VersionNumber = "1.0.0.323"
task :default => [:debug_build]
task :release => [:versioning, :release_build]
assemblyinfo :versioning do |asm|
asm.output_file = "AssemblyInfo.cs"
asm.version = @VersionNumber
asm.file_version = @VersionNumber
asm.description = "Demonstrates how to use Rake."
asm.product_name = "Rake 範例"
asm.company_name = "My Company, Inc."
asm.copyright = "Copyright (c) 2011 Huan-Lin Tsai."
end
msbuild :debug_build do |msb|
msb.properties :configuration => :Debug
msb.targets :Build
msb.solution = "RakeDemo.sln"
end
msbuild :release_build do |msb|
cp "AssemblyInfo.cs", "ConsoleApp1/Properties/AssemblyInfo.cs"
cp "AssemblyInfo.cs", "MyLib/Properties/AssemblyInfo.cs"
msb.properties :configuration => :Release
msb.targets :Build
msb.solution = "RakeDemo.sln"
end
下圖為 rakefile.rb 的解說:
在產生 AssemblyInfo.cs 時,我刻意在 product_name 屬性中使用中文字,看看能否正確處理中文字元或 Unicode 字元。建置完成後,利用檔案總管查看新產生的 ConsoleApp1.exe 的內容,結果如下圖:
圖中的「產品名稱」應該是 "Rake 範例",可是中文字變成亂碼了。試過將 rakefile.rb 以 ANSI 、UTF-8、Unicode 的字元編碼方式儲存,結果都不行。有的編碼甚至在 IronRuby 解譯檔案時就會顯示錯誤。這似乎是 IronRuby 本身的問題。
不能正確處理中文,這就得扣分了。還是等它可以正確處理中文或 Unicode 字元之後,再來試組態檔轉換的功能吧。



沒有留言: