/// <summary> /// Instantiate a new Pyro class. /// </summary> private Pyro() { this.extensions = new StringCollection(); this.unparsedArgs = new StringCollection(); this.messageHandler = new ConsoleMessageHandler("PYRO", "pyro.exe"); this.showLogo = true; this.tidy = true; this.delta = false; this.allowEmptyTransforms = false; this.setAssemblyFileVersions = false; this.inputTransforms = new Dictionary<string, string>(); this.inputTransformsOrdered = new List<string>(); // set the message handler this.Message += new MessageEventHandler(this.messageHandler.Display); this.wixVariableResolver = new WixVariableResolver(); this.wixVariableResolver.Message += new MessageEventHandler(this.messageHandler.Display); // initialize new bind path variables etc this.targetSourcePaths = new StringCollection(); this.updatedSourcePaths = new StringCollection(); this.targetNamedBindPaths = new NameValueCollection(); this.updatedNamedBindPaths = new NameValueCollection(); }
/// <summary> /// Instantiate a new Pyro class. /// </summary> private Pyro() { this.extensions = new StringCollection(); this.unparsedArgs = new StringCollection(); this.messageHandler = new ConsoleMessageHandler("PYRO", "pyro.exe"); this.showLogo = true; this.tidy = true; this.delta = false; this.allowEmptyTransforms = false; this.setAssemblyFileVersions = false; this.inputTransforms = new Dictionary <string, string>(); this.inputTransformsOrdered = new List <string>(); // set the message handler this.Message += new MessageEventHandler(this.messageHandler.Display); this.wixVariableResolver = new WixVariableResolver(); this.wixVariableResolver.Message += new MessageEventHandler(this.messageHandler.Display); // initialize new bind path variables etc this.targetSourcePaths = new StringCollection(); this.updatedSourcePaths = new StringCollection(); this.targetNamedBindPaths = new NameValueCollection(); this.updatedNamedBindPaths = new NameValueCollection(); }
public void Build() { try { // Compile all wix documents. Compile(); // Link the compiled documents into an output. Localizer localizer = new Localizer(); localizer.Message += HandleMessage; WixVariableResolver wixVariableResolver = new WixVariableResolver(); wixVariableResolver.Message += HandleMessage; Output output = Link(localizer, wixVariableResolver); // Bind everything together into the final install. Bind(output, localizer, wixVariableResolver); } catch (WixException e) { throw new System.Exception(string.Format(e.Error.ResourceManager.GetString(e.Error.ResourceName), e.Error.MessageArgs)); } }
private Output Link(Localizer localizer, WixVariableResolver wixVariableResolver) { // Create a linker. Linker linker = new Linker(); linker.Message += HandleMessage; linker.Localizer = localizer; linker.WixVariableResolver = wixVariableResolver; // Load each intermediate for each document. SectionCollection sections = new SectionCollection(); foreach (KeyValuePair <string, Wix> pair in m_wixDocuments) { string path = Path.Combine(m_buildFolder, pair.Key + File.Wixobj.Extension); Intermediate intermediate = Intermediate.Load(path, linker.TableDefinitions, false, false); sections.AddRange(intermediate.Sections); } // Link. ArrayList transforms = new ArrayList(); return(linker.Link(sections, transforms)); }
/// <summary> /// Instantiate a new Pyro class. /// </summary> private Pyro() { this.messageHandler = new ConsoleMessageHandler("PYRO", "pyro.exe"); this.showLogo = true; this.tidy = true; this.inputTransforms = new Hashtable(); // set the message handler this.Message += new MessageEventHandler(this.messageHandler.Display); this.wixVariableResolver = new WixVariableResolver(); this.wixVariableResolver.Message += new MessageEventHandler(this.messageHandler.Display); }
/// <summary> /// Rebuild the Wixlib using the original Wixlib and updated files. /// </summary> private void RebuildWixlib() { Librarian librarian = new Librarian(); WixVariableResolver wixVariableResolver = new WixVariableResolver(); BlastBinderFileManager binderFileManager = new BlastBinderFileManager(this.outputFile); if (0 == Retina.GetCabinetFileIdToFileNameMap(this.outputFile).Count) { this.messageHandler.Display(this, WixWarnings.NotABinaryWixlib(this.outputFile)); return; } Library library = Library.Load(this.outputFile, librarian.TableDefinitions, false, false); library.Save(this.outputFile, binderFileManager, wixVariableResolver); }
/// <summary> /// Instantiate a new Light class. /// </summary> private Light() { this.bindPaths = new StringCollection(); this.extensionList = new StringCollection(); this.localizationFiles = new StringCollection(); this.messageHandler = new ConsoleMessageHandler("LGHT", "light.exe"); this.inputFiles = new StringCollection(); this.invalidArgs = new StringCollection(); this.unparsedArgs = new StringCollection(); this.sourcePaths = new StringCollection(); this.showLogo = true; this.tidy = true; this.sectionIdOnRows = true; this.wixVariableResolver = new WixVariableResolver(); this.wixVariableResolver.Message += new MessageEventHandler(this.messageHandler.Display); }
/// <summary> /// Instantiate a new Light class. /// </summary> private Light() { this.basePaths = new StringCollection(); this.extensionList = new StringCollection(); this.localizationFiles = new StringCollection(); this.messageHandler = new ConsoleMessageHandler("LGHT", "light.exe"); this.inputFiles = new StringCollection(); this.sourcePaths = new StringCollection(); this.showLogo = true; this.suppressICEs = new StringCollection(); this.tidy = true; this.wixVariableResolver = new WixVariableResolver(); this.wixVariableResolver.Message += new MessageEventHandler(this.messageHandler.Display); this.validator = new Validator(); }
/// <summary> /// Instantiate a new Light class. /// </summary> private Light() { this.bindPaths = new StringCollection(); this.extensionList = new StringCollection(); this.localizationFiles = new StringCollection(); this.messageHandler = new ConsoleMessageHandler("LGHT", "light.exe"); this.inputFiles = new StringCollection(); this.invalidArgs = new StringCollection(); this.unparsedArgs = new StringCollection(); this.sourcePaths = new StringCollection(); this.showLogo = true; this.tidy = true; this.sectionIdOnRows = true; this.wixVariableResolver = new WixVariableResolver(); this.wixVariableResolver.Message += new MessageEventHandler(this.messageHandler.Display); }
private void Bind(Output output, Localizer localizer, WixVariableResolver wixVariableResolver) { // Create a binder. Binder binder = new Binder(); binder.Localizer = localizer; binder.WixVariableResolver = wixVariableResolver; binder.TempFilesLocation = m_buildFolder; try { binder.Bind(output, m_installFile); } finally { binder.DeleteTempFiles(); } }
/// <summary> /// Generates the appropriate MSI file for the package. /// </summary> /// <param name="sourceDoc">WiX document to create MSI from.</param> /// <param name="outputFile">File path for the MSI file.</param> /// <returns>True if generation works, false if anything goes wrong.</returns> private bool GenerateMsi(XmlDocument sourceDoc, string outputFile) { // Create the Compiler. Compiler compiler = new Compiler(); compiler.Message += this.core.MessageEventHandler; // Compile the source document. Intermediate intermediate = compiler.Compile(sourceDoc); if (intermediate == null) { return false; } // Create the variable resolver that will be used in the Linker and Binder. WixVariableResolver wixVariableResolver = new WixVariableResolver(); wixVariableResolver.Message += this.core.MessageEventHandler; // Create the Linker. Linker linker = new Linker(); linker.Message += this.core.MessageEventHandler; linker.WixVariableResolver = wixVariableResolver; // Load the isolatedapp.wixlib. System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); Library appLib = LoadLibraryHelper(assembly, "Microsoft.Tools.WindowsInstallerXml.Extensions.OfficeAddin.Data.OfficeAddin.wixlib", linker.TableDefinitions); // Link the compiled source document and the isolatedapp.wixlib together. SectionCollection sections = new SectionCollection(); sections.AddRange(intermediate.Sections); sections.AddRange(appLib.Sections); Output output = linker.Link(sections); if (output == null) { return false; } // Tweak the compiled output to add a few GUIDs for Components from the oaddin.wixlib. Table components = output.Tables["Component"]; foreach (Row row in components.Rows) { switch ((string)row[0]) { case "ThisApplicationVersionRegistryKeyComponent": row[1] = Guid.NewGuid().ToString("B"); break; case "ThisApplicationCacheFolderComponent": row[1] = Guid.NewGuid().ToString("B"); break; case "ThisApplicationShortcutComponent": row[1] = Guid.NewGuid().ToString("B"); break; } } // Bind the final output. Binder binder = new Binder(); binder.FileManager = new BinderFileManager(); binder.FileManager.SourcePaths.Add(Path.GetDirectoryName(outputFile)); binder.FileManager.SourcePaths.Add(this.source); binder.FileManager.SourcePaths.Add(Path.GetDirectoryName(assembly.Location)); binder.Message += this.core.MessageEventHandler; binder.WixVariableResolver = wixVariableResolver; return binder.Bind(output, outputFile); }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { try { Librarian librarian = null; SectionCollection sections = new SectionCollection(); // parse the command line this.ParseCommandLine(args); // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } if (0 == this.inputFiles.Count) { this.showHelp = true; } else if (null == this.outputFile) { if (1 < this.inputFiles.Count) { throw new ArgumentException("must specify output file when using more than one input file", "-out"); } // we'll let the linker change the extension later this.outputFile = Path.ChangeExtension(this.inputFiles[0], ".wix"); } if (this.showLogo) { Assembly litAssembly = Assembly.GetExecutingAssembly(); Console.WriteLine("Microsoft (R) Windows Installer Xml Library Tool version {0}", litAssembly.GetName().Version.ToString()); Console.WriteLine("Copyright (C) Microsoft Corporation 2003. All rights reserved."); Console.WriteLine(); } if (this.showHelp) { Console.WriteLine(" usage: lit.exe [-?] [-nologo] [-out libraryFile] objectFile [objectFile ...]"); Console.WriteLine(); Console.WriteLine(" -nologo skip printing lit logo information"); Console.WriteLine(" -out specify output file (default: write to current directory)"); Console.WriteLine(); Console.WriteLine(" -b base path to locate all files (default: current directory)"); Console.WriteLine(" -bf bind files into the library file"); Console.WriteLine(" -ext extension assembly or \"class, assembly\""); Console.WriteLine(" -loc <loc.wxl> bind localization strings from a wxl into the library file"); Console.WriteLine(" -ss suppress schema validation of documents (performance boost)"); Console.WriteLine(" -sv suppress intermediate file version mismatch checking"); Console.WriteLine(" -sw<N> suppress warning with specific message ID"); Console.WriteLine(" -wx treat warnings as errors"); Console.WriteLine(" -v verbose output"); Console.WriteLine(" -? this help information"); Console.WriteLine(); Console.WriteLine("Common extensions:"); Console.WriteLine(" .wxs - Windows installer Xml Source file"); Console.WriteLine(" .wxi - Windows installer Xml Include file"); Console.WriteLine(" .wixobj - Windows installer Xml Object file (in XML format)"); Console.WriteLine(" .wixlib - Windows installer Xml Library file (in XML format)"); Console.WriteLine(" .wixout - Windows installer Xml Output file (in XML format)"); Console.WriteLine(); Console.WriteLine(" .msm - Windows installer Merge Module"); Console.WriteLine(" .msi - Windows installer Product Database"); Console.WriteLine(" .msp - Windows installer Patch"); Console.WriteLine(" .mst - Windows installer Transform"); Console.WriteLine(" .pcp - Windows installer Patch Creation Package"); Console.WriteLine(); Console.WriteLine("For more information see: http://wix.sourceforge.net"); return(this.messageHandler.LastErrorNumber); } // create the librarian librarian = new Librarian(); librarian.Message += new MessageEventHandler(this.messageHandler.Display); if (null != this.basePaths) { foreach (string basePath in this.basePaths) { this.sourcePaths.Add(basePath); } } // load any extensions foreach (string extension in this.extensionList) { WixExtension wixExtension = WixExtension.Load(extension); librarian.AddExtension(wixExtension); // load the binder extension regardless of whether it will be used in case there is a collision if (null != wixExtension.BinderExtension) { if (null != this.binderExtension) { throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "cannot load binder extension: {0}. lit can only load one binder extension and has already loaded binder extension: {1}.", wixExtension.BinderExtension.GetType().ToString(), this.binderExtension.GetType().ToString()), "ext"); } this.binderExtension = wixExtension.BinderExtension; } } // add the sections to the librarian foreach (string inputFile in this.inputFiles) { string inputFileFullPath = Path.GetFullPath(inputFile); string dirName = Path.GetDirectoryName(inputFileFullPath); if (!this.sourcePaths.Contains(dirName)) { this.sourcePaths.Add(dirName); } // try loading as an object file try { Intermediate intermediate = Intermediate.Load(inputFileFullPath, librarian.TableDefinitions, this.suppressVersionCheck, this.suppressSchema); sections.AddRange(intermediate.Sections); continue; // next file } catch (WixNotIntermediateException) { // try another format } // try loading as a library file Library loadedLibrary = Library.Load(inputFileFullPath, librarian.TableDefinitions, this.suppressVersionCheck, this.suppressSchema); sections.AddRange(loadedLibrary.Sections); } // and now for the fun part Library library = librarian.Combine(sections); // save the library output if an error did not occur if (null != library) { if (this.bindFiles) { // if the binder extension has not been loaded yet use the built-in binder extension if (null == this.binderExtension) { this.binderExtension = new BinderExtension(); } // set the binder extension information foreach (string basePath in this.basePaths) { this.binderExtension.BasePaths.Add(basePath); } foreach (string sourcePath in this.sourcePaths) { this.binderExtension.SourcePaths.Add(sourcePath); } } else { this.binderExtension = null; } foreach (string localizationFile in this.localizationFiles) { Localization localization = Localization.Load(localizationFile, librarian.TableDefinitions, this.suppressSchema); library.AddLocalization(localization); } WixVariableResolver wixVariableResolver = new WixVariableResolver(); wixVariableResolver.Message += new MessageEventHandler(this.messageHandler.Display); library.Save(this.outputFile, this.binderExtension, wixVariableResolver); } } catch (WixException we) { this.messageHandler.Display(this, we.Error); } catch (Exception e) { this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } return(this.messageHandler.LastErrorNumber); }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { try { Librarian librarian = null; SectionCollection sections = new SectionCollection(); // parse the command line this.ParseCommandLine(args); // load any extensions List <WixExtension> loadedExtensionList = new List <WixExtension>(); foreach (string extension in this.extensionList) { WixExtension wixExtension = WixExtension.Load(extension); loadedExtensionList.Add(wixExtension); // Have the binder extension parse the command line arguments lit did not recognized. if (0 < this.unparsedArgs.Count) { this.unparsedArgs = wixExtension.ParseCommandLine(this.unparsedArgs, this.messageHandler); } } this.ParseCommandLinePassTwo(this.unparsedArgs); // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } if (0 == this.inputFiles.Count) { this.showHelp = true; } else if (null == this.outputFile) { if (1 < this.inputFiles.Count) { throw new WixException(WixErrors.MustSpecifyOutputWithMoreThanOneInput()); } this.outputFile = Path.ChangeExtension(Path.GetFileName(this.inputFiles[0]), ".wixlib"); } if (this.showLogo) { AppCommon.DisplayToolHeader(); } if (this.showHelp) { Console.WriteLine(LitStrings.HelpMessage); AppCommon.DisplayToolFooter(); return(this.messageHandler.LastErrorNumber); } foreach (string parameter in this.invalidArgs) { this.messageHandler.Display(this, WixWarnings.UnsupportedCommandLineArgument(parameter)); } this.invalidArgs = null; // create the librarian librarian = new Librarian(); librarian.Message += new MessageEventHandler(this.messageHandler.Display); librarian.ShowPedanticMessages = this.showPedanticMessages; if (null != this.bindPaths) { foreach (string bindPath in this.bindPaths) { if (-1 == bindPath.IndexOf('=')) { this.sourcePaths.Add(bindPath); } } } foreach (WixExtension wixExtension in loadedExtensionList) { librarian.AddExtension(wixExtension); // load the binder file manager regardless of whether it will be used in case there is a collision if (null != wixExtension.BinderFileManager) { if (null != this.binderFileManager) { throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, LitStrings.EXP_CannotLoadBinderFileManager, wixExtension.BinderFileManager.GetType().ToString(), this.binderFileManager.GetType().ToString()), "ext"); } this.binderFileManager = wixExtension.BinderFileManager; } } // add the sections to the librarian foreach (string inputFile in this.inputFiles) { string inputFileFullPath = Path.GetFullPath(inputFile); string dirName = Path.GetDirectoryName(inputFileFullPath); if (!this.sourcePaths.Contains(dirName)) { this.sourcePaths.Add(dirName); } // try loading as an object file try { Intermediate intermediate = Intermediate.Load(inputFileFullPath, librarian.TableDefinitions, this.suppressVersionCheck, this.suppressSchema); sections.AddRange(intermediate.Sections); continue; // next file } catch (WixNotIntermediateException) { // try another format } // try loading as a library file Library loadedLibrary = Library.Load(inputFileFullPath, librarian.TableDefinitions, this.suppressVersionCheck, this.suppressSchema); sections.AddRange(loadedLibrary.Sections); } // and now for the fun part Library library = librarian.Combine(sections); // save the library output if an error did not occur if (null != library) { if (this.bindFiles) { // if the binder file manager has not been loaded yet use the built-in binder extension if (null == this.binderFileManager) { this.binderFileManager = new BinderFileManager(); } if (null != this.bindPaths) { foreach (string bindPath in this.bindPaths) { if (-1 == bindPath.IndexOf('=')) { this.binderFileManager.BindPaths.Add(bindPath); } else { string[] namedPair = bindPath.Split('='); //It is ok to have duplicate key. this.binderFileManager.NamedBindPaths.Add(namedPair[0], namedPair[1]); } } } foreach (string sourcePath in this.sourcePaths) { this.binderFileManager.SourcePaths.Add(sourcePath); } } else { this.binderFileManager = null; } foreach (string localizationFile in this.localizationFiles) { Localization localization = Localization.Load(localizationFile, librarian.TableDefinitions, this.suppressSchema); library.AddLocalization(localization); } WixVariableResolver wixVariableResolver = new WixVariableResolver(); wixVariableResolver.Message += new MessageEventHandler(this.messageHandler.Display); library.Save(this.outputFile, this.binderFileManager, wixVariableResolver); } } catch (WixException we) { this.messageHandler.Display(this, we.Error); } catch (Exception e) { this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } return(this.messageHandler.LastErrorNumber); }
/// <summary> /// Generates the appropriate MSI file for the package. /// </summary> /// <param name="sourceDoc">WiX document to create MSI from.</param> /// <param name="outputFile">File path for the MSI file.</param> /// <returns>True if generation worked, false if there were any failures.</returns> private bool GenerateMsi(XmlDocument sourceDoc, string outputFile) { // Create the Compiler. Compiler compiler = new Compiler(); if (this.core != null) { compiler.Message += this.core.MessageEventHandler; } // Compile the source document. Intermediate intermediate = compiler.Compile(sourceDoc); if (intermediate == null) { return(false); } // Create the variable resolver that will be used in the Linker and Binder. WixVariableResolver wixVariableResolver = new WixVariableResolver(); if (this.core != null) { wixVariableResolver.Message += this.core.MessageEventHandler; } // Create the Linker. Linker linker = new Linker(); if (this.core != null) { linker.Message += this.core.MessageEventHandler; } linker.WixVariableResolver = wixVariableResolver; // Load the isolatedapp.wixlib. System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); Library appLib = LoadLibraryHelper(assembly, "WixToolset.Extensions.IsolatedApp.Data.IsolatedApp.wixlib", linker.TableDefinitions); // Link the compiled source document and the isolatedapp.wixlib together. SectionCollection sections = new SectionCollection(); sections.AddRange(intermediate.Sections); sections.AddRange(appLib.Sections); Output output = linker.Link(sections); if (output == null) { return(false); } // Tweak the compiled output to add a few GUIDs for Components from the isolatedapp.wixlib. Table components = output.Tables["Component"]; foreach (Row row in components.Rows) { switch ((string)row[0]) { case "ThisApplicationVersionRegistryKeyComponent": row[1] = String.Concat("{", Guid.NewGuid().ToString().ToUpper(), "}"); break; case "ThisApplicationCacheFolderComponent": row[1] = String.Concat("{", Guid.NewGuid().ToString().ToUpper(), "}"); break; case "ThisApplicationShortcutComponent": row[1] = String.Concat("{", Guid.NewGuid().ToString().ToUpper(), "}"); break; } } // Bind the final output. Binder binder = new Binder(); binder.FileManager = new BinderFileManager(); binder.FileManager.SourcePaths.Add(Path.GetDirectoryName(outputFile)); binder.FileManager.SourcePaths.Add(this.source); binder.FileManager.SourcePaths.Add(Path.GetDirectoryName(assembly.Location)); if (this.core != null) { binder.Message += this.core.MessageEventHandler; } binder.WixVariableResolver = wixVariableResolver; return(binder.Bind(output, outputFile)); }
/// <summary> /// Rebuild the Wixlib using the original Wixlib and updated files. /// </summary> private void RebuildWixlib() { Librarian librarian = new Librarian(); WixVariableResolver wixVariableResolver = new WixVariableResolver(); BlastBinderFileManager binderFileManager = new BlastBinderFileManager(this.outputFile); if (0 == Retina.GetCabinetFileIdToFileNameMap(this.outputFile).Count) { this.messageHandler.Display(this, WixWarnings.NotABinaryWixlib(this.outputFile)); return; } Library library = Library.Load(this.outputFile, librarian.TableDefinitions, false, false); library.Save(this.outputFile, binderFileManager, wixVariableResolver); }
/// <summary> /// Main running method for the application. /// </summary> private void Run() { WixVariableResolver wixVariableResolver = new WixVariableResolver(); // Initialize the binder from the command line. WixToolset.Binder binder = new WixToolset.Binder(); binder.CabCachePath = this.commandLine.CabCachePath; //binder.DeltaBinaryPatch = this.commandLine.Delta; //binder.ContentsFile = this.commandLine.ContentsFile; //binder.BuiltOutputsFile = this.commandLine.BuiltOutputsFile; //binder.OutputsFile = this.commandLine.OutputsFile; //binder.WixprojectFile = this.commandLine.WixprojectFile; //binder.BindPaths.AddRange(this.commandLine.BindPaths); binder.TargetBindPaths.AddRange(this.commandLine.TargetBindPaths); binder.UpdatedBindPaths.AddRange(this.commandLine.UpdatedBindPaths); //binder.CabbingThreadCount = this.commandLine.CabbingThreadCount; //binder.DefaultCompressionLevel = this.commandLine.DefaultCompressionLevel; //binder.ExactAssemblyVersions = this.commandLine.ExactAssemblyVersions; binder.SuppressAclReset = this.commandLine.SuppressAclReset; //binder.SuppressLayout = this.commandLine.SuppressLayout; binder.SuppressValidation = true; binder.PdbFile = this.commandLine.SuppressWixPdb ? null : this.commandLine.PdbFile; binder.TempFilesLocation = AppCommon.GetTempLocation(); binder.WixVariableResolver = wixVariableResolver; foreach (IBinderExtension extension in this.binderExtensions) { binder.AddExtension(extension); } foreach (IBinderFileManager fileManager in this.fileManagers) { binder.AddExtension(fileManager); } // Create and configure the patch Patch patch = new Patch(); patch.Load(this.commandLine.InputFile); patch.AttachTransforms(this.commandLine.PatchTransforms); bool tidy = true; // clean up after ourselves by default. try { // Bind the patch to an msp. binder.Bind(patch.PatchOutput, this.commandLine.OutputFile); } catch (WixException we) { if (we is WixInvalidIdtException) { tidy = false; } throw; } catch (Exception) { tidy = false; throw; } finally { if (null != binder) { binder.Cleanup(tidy); } } return; }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { try { Librarian librarian = null; SectionCollection sections = new SectionCollection(); // parse the command line this.ParseCommandLine(args); // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (this.messageHandler.EncounteredError) { return this.messageHandler.LastErrorNumber; } if (0 == this.inputFiles.Count) { this.showHelp = true; } else if (null == this.outputFile) { if (1 < this.inputFiles.Count) { throw new WixException(WixErrors.MustSpecifyOutputWithMoreThanOneInput()); } this.outputFile = Path.ChangeExtension(Path.GetFileName(this.inputFiles[0]), ".wixlib"); } if (this.showLogo) { AppCommon.DisplayToolHeader(); } if (this.showHelp) { Console.WriteLine(LitStrings.HelpMessage); AppCommon.DisplayToolFooter(); return this.messageHandler.LastErrorNumber; } foreach (string parameter in this.invalidArgs) { this.messageHandler.Display(this, WixWarnings.UnsupportedCommandLineArgument(parameter)); } this.invalidArgs = null; // create the librarian librarian = new Librarian(); librarian.Message += new MessageEventHandler(this.messageHandler.Display); librarian.ShowPedanticMessages = this.showPedanticMessages; if (null != this.bindPaths) { foreach (string bindPath in this.bindPaths) { if (-1 == bindPath.IndexOf('=')) { this.sourcePaths.Add(bindPath); } } } // load any extensions foreach (string extension in this.extensionList) { WixExtension wixExtension = WixExtension.Load(extension); librarian.AddExtension(wixExtension); // load the binder file manager regardless of whether it will be used in case there is a collision if (null != wixExtension.BinderFileManager) { if (null != this.binderFileManager) { throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, LitStrings.EXP_CannotLoadBinderFileManager, wixExtension.BinderFileManager.GetType().ToString(), this.binderFileManager.GetType().ToString()), "ext"); } this.binderFileManager = wixExtension.BinderFileManager; } } // add the sections to the librarian foreach (string inputFile in this.inputFiles) { string inputFileFullPath = Path.GetFullPath(inputFile); string dirName = Path.GetDirectoryName(inputFileFullPath); if (!this.sourcePaths.Contains(dirName)) { this.sourcePaths.Add(dirName); } // try loading as an object file try { Intermediate intermediate = Intermediate.Load(inputFileFullPath, librarian.TableDefinitions, this.suppressVersionCheck, this.suppressSchema); sections.AddRange(intermediate.Sections); continue; // next file } catch (WixNotIntermediateException) { // try another format } // try loading as a library file Library loadedLibrary = Library.Load(inputFileFullPath, librarian.TableDefinitions, this.suppressVersionCheck, this.suppressSchema); sections.AddRange(loadedLibrary.Sections); } // and now for the fun part Library library = librarian.Combine(sections); // save the library output if an error did not occur if (null != library) { if (this.bindFiles) { // if the binder file manager has not been loaded yet use the built-in binder extension if (null == this.binderFileManager) { this.binderFileManager = new BinderFileManager(); } if (null != this.bindPaths) { foreach (string bindPath in this.bindPaths) { if (-1 == bindPath.IndexOf('=')) { this.binderFileManager.BindPaths.Add(bindPath); } else { string[] namedPair = bindPath.Split('='); //It is ok to have duplicate key. this.binderFileManager.NamedBindPaths.Add(namedPair[0], namedPair[1]); } } } foreach (string sourcePath in this.sourcePaths) { this.binderFileManager.SourcePaths.Add(sourcePath); } } else { this.binderFileManager = null; } foreach (string localizationFile in this.localizationFiles) { Localization localization = Localization.Load(localizationFile, librarian.TableDefinitions, this.suppressSchema); library.AddLocalization(localization); } WixVariableResolver wixVariableResolver = new WixVariableResolver(); wixVariableResolver.Message += new MessageEventHandler(this.messageHandler.Display); library.Save(this.outputFile, this.binderFileManager, wixVariableResolver); } } catch (WixException we) { this.messageHandler.Display(this, we.Error); } catch (Exception e) { this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } return this.messageHandler.LastErrorNumber; }
/// <summary> /// Generates the appropriate MSI file for the package. /// </summary> /// <param name="sourceDoc">WiX document to create MSI from.</param> /// <param name="filePath">File path for the RSS feed.</param> private void GenerateMsi(XmlDocument sourceDoc, string filePath) { // Compile Compiler compiler = new Compiler(); compiler.Message += new MessageEventHandler(this.MessageHandler); Intermediate intermediate = compiler.Compile(sourceDoc); if (intermediate == null) { return; } // locate the applib.wixlib string assemblyPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string applibPath = Path.Combine(assemblyPath, "applib.wixlib"); if (!File.Exists(applibPath)) { this.OnMessage(ClickThroughErrors.CannotLoadApplib(applibPath)); return; } WixVariableResolver wixVariableResolver = new WixVariableResolver(); wixVariableResolver.Message += new MessageEventHandler(this.MessageHandler); // create the linker Linker linker = new Linker(); linker.Message += new MessageEventHandler(this.MessageHandler); linker.WixVariableResolver = wixVariableResolver; // load applib.wixlib Library lowImpactAppLib = Library.Load(applibPath, linker.TableDefinitions, false, false); SectionCollection sections = new SectionCollection(); sections.AddRange(intermediate.Sections); sections.AddRange(lowImpactAppLib.Sections); // Link Output output = linker.Link(sections); if (output == null) { return; } Table components = output.Tables["Component"]; foreach (Row row in components.Rows) { switch ((string)row[0]) { case "ThisApplicationVersionRegistryKeyComponent": row[1] = String.Concat("{", Guid.NewGuid().ToString().ToUpper(), "}"); break; case "ThisApplicationCacheFolderComponent": row[1] = String.Concat("{", Guid.NewGuid().ToString().ToUpper(), "}"); break; case "ThisApplicationShortcutComponent": row[1] = String.Concat("{", Guid.NewGuid().ToString().ToUpper(), "}"); break; } } // Bind Binder binder = new Binder(); binder.Extension = new BinderExtension(); binder.Extension.SourcePaths.Add(Path.GetDirectoryName(filePath)); binder.Extension.SourcePaths.Add(assemblyPath); binder.WixVariableResolver = wixVariableResolver; binder.Message += new MessageEventHandler(this.MessageHandler); binder.Bind(output, filePath); return; }
/// <summary> /// Generates the appropriate MSI file for the package. /// </summary> /// <param name="sourceDoc">WiX document to create MSI from.</param> /// <param name="filePath">File path for the RSS feed.</param> private void GenerateMsi(XmlDocument sourceDoc, string filePath) { // Compile Compiler compiler = new Compiler(); compiler.Message += new MessageEventHandler(this.MessageHandler); Intermediate intermediate = compiler.Compile(sourceDoc); if (intermediate == null) { return; } // locate the applib.wixlib string assemblyPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string applibPath = Path.Combine(assemblyPath, "applib.wixlib"); if (!File.Exists(applibPath)) { this.OnMessage(ClickThroughErrors.CannotLoadApplib(applibPath)); return; } WixVariableResolver wixVariableResolver = new WixVariableResolver(); wixVariableResolver.Message += new MessageEventHandler(this.MessageHandler); // create the linker Linker linker = new Linker(); linker.Message += new MessageEventHandler(this.MessageHandler); linker.WixVariableResolver = wixVariableResolver; // load applib.wixlib Library lowImpactAppLib = Library.Load(applibPath, linker.TableDefinitions, false, false); SectionCollection sections = new SectionCollection(); sections.AddRange(intermediate.Sections); sections.AddRange(lowImpactAppLib.Sections); // Link Output output = linker.Link(sections); if (output == null) { return; } Table components = output.Tables["Component"]; foreach (Row row in components.Rows) { switch ((string)row[0]) { case "ThisApplicationVersionRegistryKeyComponent": row[1] = String.Concat("{", Guid.NewGuid().ToString().ToUpper(), "}"); break; case "ThisApplicationCacheFolderComponent": row[1] = String.Concat("{", Guid.NewGuid().ToString().ToUpper(), "}"); break; case "ThisApplicationShortcutComponent": row[1] = String.Concat("{", Guid.NewGuid().ToString().ToUpper(), "}"); break; } } // Bind Binder binder = new Binder(); binder.Extension = new BinderExtension(); binder.Extension.SourcePaths.Add(Path.GetDirectoryName(filePath)); binder.Extension.SourcePaths.Add(assemblyPath); binder.WixVariableResolver = wixVariableResolver; binder.Message += new MessageEventHandler(this.MessageHandler); binder.Bind(output, filePath); return; }
/// <param name="output">Internal representation of the msi database to operate upon.</param> /// <param name="delayedFields">The fields which had resolution delayed.</param> /// <param name="variableCache">The file information to use when resolving variables.</param> /// <param name="modularizationGuid">The modularization guid (used in case of a merge module).</param> public void Execute() { List <DelayedField> deferredFields = new List <DelayedField>(); foreach (DelayedField delayedField in this.DelayedFields) { try { Row propertyRow = delayedField.Row; // process properties first in case they refer to other binder variables if ("Property" == propertyRow.Table.Name) { string value = WixVariableResolver.ResolveDelayedVariables(propertyRow.SourceLineNumbers, (string)delayedField.Field.Data, this.VariableCache); // update the variable cache with the new value string key = String.Concat("property.", BindDatabaseCommand.Demodularize(this.OutputType, this.ModularizationGuid, (string)propertyRow[0])); this.VariableCache[key] = value; // update the field data delayedField.Field.Data = value; } else { deferredFields.Add(delayedField); } } catch (WixException we) { Messaging.Instance.OnMessage(we.Error); continue; } } // add specialization for ProductVersion fields string keyProductVersion = "property.ProductVersion"; if (this.VariableCache.ContainsKey(keyProductVersion)) { string value = this.VariableCache[keyProductVersion]; Version productVersion = null; try { productVersion = new Version(value); // Don't add the variable if it already exists (developer defined a property with the same name). string fieldKey = String.Concat(keyProductVersion, ".Major"); if (!this.VariableCache.ContainsKey(fieldKey)) { this.VariableCache[fieldKey] = productVersion.Major.ToString(CultureInfo.InvariantCulture); } fieldKey = String.Concat(keyProductVersion, ".Minor"); if (!this.VariableCache.ContainsKey(fieldKey)) { this.VariableCache[fieldKey] = productVersion.Minor.ToString(CultureInfo.InvariantCulture); } fieldKey = String.Concat(keyProductVersion, ".Build"); if (!this.VariableCache.ContainsKey(fieldKey)) { this.VariableCache[fieldKey] = productVersion.Build.ToString(CultureInfo.InvariantCulture); } fieldKey = String.Concat(keyProductVersion, ".Revision"); if (!this.VariableCache.ContainsKey(fieldKey)) { this.VariableCache[fieldKey] = productVersion.Revision.ToString(CultureInfo.InvariantCulture); } } catch { // Ignore the error introduced by new behavior. } } // process the remaining fields in case they refer to property binder variables foreach (DelayedField delayedField in deferredFields) { try { delayedField.Field.Data = WixVariableResolver.ResolveDelayedVariables(delayedField.Row.SourceLineNumbers, (string)delayedField.Field.Data, this.VariableCache); } catch (WixException we) { Messaging.Instance.OnMessage(we.Error); continue; } } }
private void Run() { // Initialize the variable resolver from the command line. WixVariableResolver wixVariableResolver = new WixVariableResolver(); foreach (var wixVar in this.commandLine.Variables) { wixVariableResolver.AddVariable(wixVar.Key, wixVar.Value); } // Initialize the linker from the command line. Linker linker = new Linker(); linker.UnreferencedSymbolsFile = this.commandLine.UnreferencedSymbolsFile; linker.ShowPedanticMessages = this.commandLine.ShowPedanticMessages; linker.WixVariableResolver = wixVariableResolver; foreach (IExtensionData data in this.extensionData) { linker.AddExtensionData(data); } // Initialize the binder from the command line. WixToolset.Binder binder = new WixToolset.Binder(); binder.CabCachePath = this.commandLine.CabCachePath; binder.ReuseCabinets = this.commandLine.ReuseCabinets; binder.ContentsFile = this.commandLine.ContentsFile; binder.BuiltOutputsFile = this.commandLine.BuiltOutputsFile; binder.OutputsFile = this.commandLine.OutputsFile; binder.WixprojectFile = this.commandLine.WixprojectFile; binder.BindPaths.AddRange(this.commandLine.BindPaths); binder.CabbingThreadCount = this.commandLine.CabbingThreadCount; binder.DefaultCompressionLevel = this.commandLine.DefaultCompressionLevel; binder.ExactAssemblyVersions = this.commandLine.ExactAssemblyVersions; binder.Ices.AddRange(this.commandLine.Ices); binder.SuppressIces.AddRange(this.commandLine.SuppressIces); binder.SetMsiAssemblyNameFileVersion = this.commandLine.SetMsiAssemblyNameFileVersion; binder.SuppressAclReset = this.commandLine.SuppressAclReset; binder.SuppressLayout = this.commandLine.SuppressLayout; binder.SuppressValidation = this.commandLine.SuppressValidation; binder.PdbFile = this.commandLine.SuppressWixPdb ? null : this.commandLine.PdbFile; binder.TempFilesLocation = Environment.GetEnvironmentVariable("WIX_TEMP") ?? Path.GetTempPath(); binder.WixVariableResolver = wixVariableResolver; foreach (IBinderExtension extension in this.binderExtensions) { binder.AddExtension(extension); } foreach (IBinderFileManager fm in this.fileManagers) { binder.AddExtension(fm); } // Initialize the localizer. Localizer localizer = this.InitializeLocalization(linker.TableDefinitions); if (Messaging.Instance.EncounteredError) { return; } wixVariableResolver.Localizer = localizer; linker.Localizer = localizer; binder.Localizer = localizer; // Loop through all the believed object files. SectionCollection sections = new SectionCollection(); Output output = null; foreach (string inputFile in this.commandLine.Files) { string inputFileFullPath = Path.GetFullPath(inputFile); // try loading as an object file try { Intermediate intermediate = Intermediate.Load(inputFileFullPath, linker.TableDefinitions, this.commandLine.SuppressVersionCheck, true); sections.AddRange(intermediate.Sections); continue; // next file } catch (WixNotIntermediateException) { // try another format } // try loading as a library file try { Library library = Library.Load(inputFileFullPath, linker.TableDefinitions, this.commandLine.SuppressVersionCheck, true); library.GetLocalizations(this.commandLine.Cultures, localizer); sections.AddRange(library.Sections); continue; // next file } catch (WixNotLibraryException) { // try another format } // try loading as an output file output = Output.Load(inputFileFullPath, this.commandLine.SuppressVersionCheck, true); } // Stop processing if any errors were found loading object files. if (Messaging.Instance.EncounteredError) { return; } // and now for the fun part if (null == output) { OutputType expectedOutputType = OutputType.Unknown; if (!String.IsNullOrEmpty(this.commandLine.OutputFile)) { expectedOutputType = Output.GetOutputType(Path.GetExtension(this.commandLine.OutputFile)); } ArrayList transforms = new ArrayList(); output = linker.Link(sections, transforms, expectedOutputType); // If an error occurred during linking, stop processing. if (null == output) { return; } } else if (0 != sections.Count) { throw new InvalidOperationException(LightStrings.EXP_CannotLinkObjFilesWithOutpuFile); } bool tidy = true; // clean up after ourselves by default. try { // only output the xml if its a patch build or user specfied to only output wixout string outputFile = this.commandLine.OutputFile; string outputExtension = Path.GetExtension(outputFile); if (this.commandLine.OutputXml || OutputType.Patch == output.Type) { if (String.IsNullOrEmpty(outputExtension) || outputExtension.Equals(".wix", StringComparison.Ordinal)) { outputExtension = (OutputType.Patch == output.Type) ? ".wixmsp" : ".wixout"; outputFile = Path.ChangeExtension(outputFile, outputExtension); } output.Save(outputFile, null, wixVariableResolver, binder.TempFilesLocation); } else // finish creating the MSI/MSM { if (String.IsNullOrEmpty(outputExtension) || outputExtension.Equals(".wix", StringComparison.Ordinal)) { outputExtension = Output.GetExtension(output.Type); outputFile = Path.ChangeExtension(outputFile, outputExtension); } binder.Bind(output, outputFile); } } catch (WixException we) // keep files around for debugging IDT issues. { if (we is WixInvalidIdtException) { tidy = false; } throw; } catch (Exception) // keep files around for debugging unexpected exceptions. { tidy = false; throw; } finally { if (null != binder) { binder.Cleanup(tidy); } } return; }
private void Run(IMessaging messaging) { #if false // Initialize the variable resolver from the command line. WixVariableResolver wixVariableResolver = new WixVariableResolver(); foreach (var wixVar in this.commandLine.Variables) { wixVariableResolver.AddVariable(wixVar.Key, wixVar.Value); } // Initialize the linker from the command line. Linker linker = new Linker(); linker.UnreferencedSymbolsFile = this.commandLine.UnreferencedSymbolsFile; linker.ShowPedanticMessages = this.commandLine.ShowPedanticMessages; linker.WixVariableResolver = wixVariableResolver; foreach (IExtensionData data in this.extensionData) { linker.AddExtensionData(data); } // Initialize the binder from the command line. WixToolset.Binder binder = new WixToolset.Binder(); binder.CabCachePath = this.commandLine.CabCachePath; binder.ContentsFile = this.commandLine.ContentsFile; binder.BuiltOutputsFile = this.commandLine.BuiltOutputsFile; binder.OutputsFile = this.commandLine.OutputsFile; binder.WixprojectFile = this.commandLine.WixprojectFile; binder.BindPaths.AddRange(this.commandLine.BindPaths); binder.CabbingThreadCount = this.commandLine.CabbingThreadCount; if (this.commandLine.DefaultCompressionLevel.HasValue) { binder.DefaultCompressionLevel = this.commandLine.DefaultCompressionLevel.Value; } binder.Ices.AddRange(this.commandLine.Ices); binder.SuppressIces.AddRange(this.commandLine.SuppressIces); binder.SuppressAclReset = this.commandLine.SuppressAclReset; binder.SuppressLayout = this.commandLine.SuppressLayout; binder.SuppressValidation = this.commandLine.SuppressValidation; binder.PdbFile = this.commandLine.SuppressWixPdb ? null : this.commandLine.PdbFile; binder.TempFilesLocation = AppCommon.GetTempLocation(); binder.WixVariableResolver = wixVariableResolver; foreach (IBinderExtension extension in this.binderExtensions) { binder.AddExtension(extension); } foreach (IBinderFileManager fileManager in this.fileManagers) { binder.AddExtension(fileManager); } // Initialize the localizer. Localizer localizer = this.InitializeLocalization(linker.TableDefinitions); if (messaging.EncounteredError) { return; } wixVariableResolver.Localizer = localizer; linker.Localizer = localizer; binder.Localizer = localizer; // Loop through all the believed object files. List <Section> sections = new List <Section>(); Output output = null; foreach (string inputFile in this.commandLine.Files) { string inputFileFullPath = Path.GetFullPath(inputFile); FileFormat format = FileStructure.GuessFileFormatFromExtension(Path.GetExtension(inputFileFullPath)); bool retry; do { retry = false; try { switch (format) { case FileFormat.Wixobj: Intermediate intermediate = Intermediate.Load(inputFileFullPath, linker.TableDefinitions, this.commandLine.SuppressVersionCheck); sections.AddRange(intermediate.Sections); break; case FileFormat.Wixlib: Library library = Library.Load(inputFileFullPath, linker.TableDefinitions, this.commandLine.SuppressVersionCheck); AddLibraryLocalizationsToLocalizer(library, this.commandLine.Cultures, localizer); sections.AddRange(library.Sections); break; default: output = Output.Load(inputFileFullPath, this.commandLine.SuppressVersionCheck); break; } } catch (WixUnexpectedFileFormatException e) { format = e.FileFormat; retry = (FileFormat.Wixobj == format || FileFormat.Wixlib == format || FileFormat.Wixout == format); // .wixobj, .wixout and .wixout are supported by light. if (!retry) { messaging.OnMessage(e.Error); } } } while (retry); } // Stop processing if any errors were found loading object files. if (messaging.EncounteredError) { return; } // and now for the fun part if (null == output) { OutputType expectedOutputType = OutputType.Unknown; if (!String.IsNullOrEmpty(this.commandLine.OutputFile)) { expectedOutputType = Output.GetOutputType(Path.GetExtension(this.commandLine.OutputFile)); } output = linker.Link(sections, expectedOutputType); // If an error occurred during linking, stop processing. if (null == output) { return; } } else if (0 != sections.Count) { throw new InvalidOperationException(LightStrings.EXP_CannotLinkObjFilesWithOutpuFile); } bool tidy = true; // clean up after ourselves by default. try { // only output the xml if its a patch build or user specfied to only output wixout string outputFile = this.commandLine.OutputFile; string outputExtension = Path.GetExtension(outputFile); if (this.commandLine.OutputXml || OutputType.Patch == output.Type) { if (String.IsNullOrEmpty(outputExtension) || outputExtension.Equals(".wix", StringComparison.Ordinal)) { outputExtension = (OutputType.Patch == output.Type) ? ".wixmsp" : ".wixout"; outputFile = Path.ChangeExtension(outputFile, outputExtension); } output.Save(outputFile); } else // finish creating the MSI/MSM { if (String.IsNullOrEmpty(outputExtension) || outputExtension.Equals(".wix", StringComparison.Ordinal)) { outputExtension = Output.GetExtension(output.Type); outputFile = Path.ChangeExtension(outputFile, outputExtension); } binder.Bind(output, outputFile); } } catch (WixException we) // keep files around for debugging IDT issues. { if (we is WixInvalidIdtException) { tidy = false; } throw; } catch (Exception) // keep files around for debugging unexpected exceptions. { tidy = false; throw; } finally { if (null != binder) { binder.Cleanup(tidy); } } return; #endif }