Wix 安装部署教程(十六) -- 自动生成多语言文件
生活随笔
收集整理的這篇文章主要介紹了
Wix 安装部署教程(十六) -- 自动生成多语言文件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Wix 安裝部署教程(十六) -- 自動生成多語言文件 原文:Wix 安裝部署教程(十六) -- 自動生成多語言文件
? ? ?因為持續集成需要,所有項目編譯完之后生成一個多語言的安裝包。之前生成mst文件都是手動操作,而且mst文件必須每次重新和新的安裝包“關聯”,否則中文的安裝包去調用英文的資源的時候就會報類似于“類型轉換失敗”的錯誤?;谶@兩點,有必要程序化這個流程,不然每次打包都得找我了。以下是程序的記錄。比較簡單。
? ? ?其實就是用程序調用cmd,再次之前,請記得將wix的bin目錄加入到系統變量中。否則命令不會被識別;然后將程序執行目錄指向目標目錄。?
static void Main(string[] args){if (args.Length < 1){return;}Console.WriteLine(args[0]);var path = args[0];// var path =MsiPath; Console.WriteLine("正在執行:" + DateTime.Now);var p = new Process{StartInfo ={FileName = "cmd.exe ",UseShellExecute = false,RedirectStandardInput = true,RedirectStandardOutput = true,RedirectStandardError = true,CreateNoWindow = false,WorkingDirectory = path}};try{p.Start();if (!Init(p, path)){Console.WriteLine("初始化失敗");p.Close();return;}//合并語言 ExcComand(p, CommandLines.LanZh_TW);ExcComand(p, CommandLines.LanZh_CN);ExcComand(p, CommandLines.LanEN_US);//關聯語言 ExcComand(p, CommandLines.CombanLanZh_cn);//測試安裝包// ExcComand(p, CommandLines.Testzh_Tw);//p.WaitForExit(); p.Close();Console.WriteLine("Complete" + DateTime.Now);}catch (Exception e1){Console.WriteLine("error" + e1.Message);}}? 先初始化,確保安裝文件、vbs文件和mst文件都存在。
private static string[] lans = { "zh-cn", "en-us", "zh-tw" };private static bool Init(Process p, string path){//多語言安裝包是否存在 foreach (var lan in lans){var lanPath = Path.Combine(path, lan, SoftName);if (!File.Exists(lanPath)){Console.WriteLine("{0}安裝包不存在!",lan);return false;}}//保證兩個文件CopyFileIfNotExist(path,"WixSubStg.vbs");CopyFileIfNotExist(path, "WiLangId.vbs");//變形文件是否存在var twmst = Path.Combine(path, "transforms", "zh-tw.mst");if (!File.Exists(twmst)){GetTransforms(p);}//再檢測一次return File.Exists(twmst);}這兩個vbs文件,在教程十三里面有提供。 最后在檢查一次mst文件就是確保mst文件的存在。變形文件是我們多語言安裝包的關鍵。
/// <summary>/// 生成變形文件/// </summary>/// <param name="p"></param>private static void GetTransforms(Process p){ExcComand(p, CommandLines.EnToZh);ExcComand(p, CommandLines.EnToTw);ExcComand(p, CommandLines.ZhToEn);}private static void ExcComand(Process p, string command){p.StandardInput.WriteLine(command);Console.WriteLine("command:" + command);Thread.Sleep(1500);} View Code而commandLines 這個類里面就包含了這次所會用到的命令。
public class CommandLines{//對應繁體public static string LanZh_TW = @"WixSubStg.vbs zh-cn\DIAViewSetup.msi transforms\zh-tw.mst 1028";//對應中文public static string LanZh_CN = @"WixSubStg.vbs zh-cn\DIAViewSetup.msi transforms\zh-cn.mst 2052";//對應英文public static string LanEN_US = @"WixSubStg.vbs zh-cn\DIAViewSetup.msi transforms\en-us.mst 1033";//合成語言安裝包 ,默認是中文public static string CombanLanZh_cn = @"WiLangId.vbs zh-cn\DIAViewSetup.msi Package 1028,2052,1033";//測試繁體安裝包public static string Testzh_Tw = @"msiexec /i zh-cn\DIAViewSetup.msi TRANSFORMS=transforms\zh-tw.mst";//測試中文安裝包public static string Testzh_Cn = @"msiexec /i zh-cn\DIAViewSetup.msi TRANSFORMS=transforms\zh-cn.mst";//測試英文安裝包public static string Testen_US = @"msiexec /i zh-cn\DIAViewSetup.msi TRANSFORMS=transforms\en-us.mst";//生成英文資源public static string EnToZh = @"torch.exe -t language en-us\DIAViewSetup.msi zh-cn\DIAViewSetup.msi -out transforms\zh-cn.mst";//生成中文資源public static string EnToTw = @"torch.exe -t language en-us\DIAViewSetup.msi zh-tw\DIAViewSetup.msi -out transforms\zh-tw.mst";//生成繁體資源public static string ZhToEn = @"torch.exe -t language zh-cn\DIAViewSetup.msi en-us\DIAViewSetup.msi -out transforms\en-us.mst";} View Code最后的執行結果如下。 這里是以zh-cn為基礎。合成之后的安裝包就可以根據系統環境自動切換語言,如果不是關聯的語言之一就顯示默認語言。
?當然,主要的目的是可以讓他可以根據用戶的選擇來顯示不同的語言界面。
?
posted on 2018-05-18 09:22 NET未來之路 閱讀(...) 評論(...) 編輯 收藏轉載于:https://www.cnblogs.com/lonelyxmas/p/9054574.html
總結
以上是生活随笔為你收集整理的Wix 安装部署教程(十六) -- 自动生成多语言文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hdu 2191 悼念512汶川大地震遇
- 下一篇: holiday