static async Task createMsiPackage(string setupExe, IPackage package) { var pathToWix = pathToWixTools(); var setupExeDir = Path.GetDirectoryName(setupExe); var company = String.Join(",", package.Authors); var templateText = File.ReadAllText(Path.Combine(pathToWix, "template.wxs")); var templateData = new Dictionary<string, string> { { "Id", package.Id }, { "Title", package.Title }, { "Author", company }, { "Version", Regex.Replace(package.Version.ToString(), @"-.*$", "") }, { "Summary", package.Summary ?? package.Description ?? package.Id }, }; // NB: We need some GUIDs that are based on the package ID, but unique (i.e. // "Unique but consistent"). for (int i=1; i <= 10; i++) { templateData[String.Format("IdAsGuid{0}", i)] = Utility.CreateGuidFromHash(String.Format("{0}:{1}", package.Id, i)).ToString(); } var templateResult = CopStache.Render(templateText, templateData); var wxsTarget = Path.Combine(setupExeDir, "Setup.wxs"); File.WriteAllText(wxsTarget, templateResult, Encoding.UTF8); var candleParams = String.Format("-nologo -ext WixNetFxExtension -out \"{0}\" \"{1}\"", wxsTarget.Replace(".wxs", ".wixobj"), wxsTarget); var processResult = await Utility.InvokeProcessAsync( Path.Combine(pathToWix, "candle.exe"), candleParams, CancellationToken.None, setupExeDir); if (processResult.Item1 != 0) { var msg = String.Format( "Failed to compile WiX template, command invoked was: '{0} {1}'\n\nOutput was:\n{2}", "candle.exe", candleParams, processResult.Item2); throw new Exception(msg); } var lightParams = String.Format("-ext WixNetFxExtension -sval -out \"{0}\" \"{1}\"", wxsTarget.Replace(".wxs", ".msi"), wxsTarget.Replace(".wxs", ".wixobj")); processResult = await Utility.InvokeProcessAsync( Path.Combine(pathToWix, "light.exe"), lightParams, CancellationToken.None, setupExeDir); if (processResult.Item1 != 0) { var msg = String.Format( "Failed to link WiX template, command invoked was: '{0} {1}'\n\nOutput was:\n{2}", "light.exe", lightParams, processResult.Item2); throw new Exception(msg); } var toDelete = new[] { wxsTarget, wxsTarget.Replace(".wxs", ".wixobj"), wxsTarget.Replace(".wxs", ".wixpdb"), }; await Utility.ForEachAsync(toDelete, x => Utility.DeleteFileHarder(x)); }
static async Task createMsiPackage(string setupExe, IPackage package) { var pathToWix = pathToWixTools(); var setupExeDir = Path.GetDirectoryName(setupExe); var company = String.Join(",", package.Authors); var templateText = File.ReadAllText(Path.Combine(pathToWix, "template.wxs")); var templateResult = CopStache.Render(templateText, new Dictionary <string, string> { { "Id", package.Id }, { "Title", package.Title }, { "Author", company }, { "Summary", package.Summary ?? package.Description ?? package.Id }, }); var wxsTarget = Path.Combine(setupExeDir, "Setup.wxs"); File.WriteAllText(wxsTarget, templateResult, Encoding.UTF8); var candleParams = String.Format("-nologo -ext WixNetFxExtension -out \"{0}\" \"{1}\"", wxsTarget.Replace(".wxs", ".wixobj"), wxsTarget); var processResult = await Utility.InvokeProcessAsync( Path.Combine(pathToWix, "candle.exe"), candleParams, CancellationToken.None); if (processResult.Item1 != 0) { var msg = String.Format( "Failed to compile WiX template, command invoked was: '{0} {1}'\n\nOutput was:\n{2}", "candle.exe", candleParams, processResult.Item2); throw new Exception(msg); } var lightParams = String.Format("-ext WixNetFxExtension -sval -out \"{0}\" \"{1}\"", wxsTarget.Replace(".wxs", ".msi"), wxsTarget.Replace(".wxs", ".wixobj")); processResult = await Utility.InvokeProcessAsync( Path.Combine(pathToWix, "light.exe"), lightParams, CancellationToken.None); if (processResult.Item1 != 0) { var msg = String.Format( "Failed to link WiX template, command invoked was: '{0} {1}'\n\nOutput was:\n{2}", "light.exe", lightParams, processResult.Item2); throw new Exception(msg); } var toDelete = new[] { wxsTarget, wxsTarget.Replace(".wxs", ".wixobj"), wxsTarget.Replace(".wxs", ".wixpdb"), }; await Utility.ForEachAsync(toDelete, x => Utility.DeleteFileHarder(x)); }
static void createMsiElectron(string setupExe, IPackage package) { var templateText = File.ReadAllText(Path.Combine(pathToWixTools(), "template.wxs")); var templateData = new Dictionary <string, string> { { "Id", package.Id }, { "Title", package.Title }, { "Author", String.Join(",", package.Authors) }, { "Version", Regex.Replace(package.Version.ToString(), @"-.*$", "") }, { "Summary", package.Summary ?? package.Description ?? package.Id }, { "SetupExecutable", setupExe }, }; // NB: We need some GUIDs that are based on the package ID, but unique (i.e. // "Unique but consistent"). for (int i = 1; i <= 10; i++) { templateData[String.Format("IdAsGuid{0}", i)] = Utility.CreateGuidFromHash(String.Format("{0}:{1}", package.Id, i)).ToString(); } File.WriteAllText(Path.Combine(Path.GetDirectoryName(setupExe), "Setup.wxs"), CopStache.Render(templateText, templateData), Encoding.UTF8); }