/// <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 { FileInfo currentFile = null; // 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.FoundError) { return(this.messageHandler.PostProcess()); } if (0 == this.sourceFiles.Count) { this.showHelp = true; } else if (1 < this.sourceFiles.Count && null != this.outputFile) { throw new ArgumentException("cannot specify more than one source file with single output file. Either specify an output directory for the -out argument by ending the argument with a '\\' or remove the -out argument to have the source files compiled to the current directory.", "-out"); } if (this.showLogo) { Assembly candleAssembly = Assembly.GetExecutingAssembly(); Console.WriteLine("Microsoft (R) Windows Installer Xml Compiler version {0}", candleAssembly.GetName().Version.ToString()); Console.WriteLine("Copyright (C) Microsoft Corporation 2003. All rights reserved."); Console.WriteLine(); } if (this.showHelp) { Console.WriteLine(" usage: candle.exe [-?] [-nologo] [-out outputFile] sourceFile [sourceFile ...]"); Console.WriteLine(); Console.WriteLine(" -d<name>=<value> define a parameter for the preprocessor"); Console.WriteLine(" -p<file> preprocess to a file (or stdout if no file supplied)"); Console.WriteLine(" -I<dir> add to include search path"); Console.WriteLine(" -nologo skip printing candle logo information"); Console.WriteLine(" -out specify output file (default: write to current directory)"); Console.WriteLine(" -pedantic:<level> pedantic checks (levels: easy, heroic, legendary)"); Console.WriteLine(" -ss suppress schema validation of documents (performance boost)"); Console.WriteLine(" -ust use small table definitions (for backwards compatiblity)"); Console.WriteLine(" -trace show source trace for errors, warnings, and verbose messages"); Console.WriteLine(" -ext extension (class, assembly), should extend CompilerExtension"); Console.WriteLine(" -zs only do validation of documents (no output)"); Console.WriteLine(" -wx treat warnings as errors"); Console.WriteLine(" -w<N> set the warning level (0: show all, 3: show none)"); Console.WriteLine(" -sw suppress all warnings (same as -w3)"); Console.WriteLine(" -sw<N> suppress warning with specific message ID"); Console.WriteLine(" -v verbose output (same as -v2)"); Console.WriteLine(" -v<N> sets the level of verbose output (0: most output, 3: none)"); 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(" .wxl - Windows installer Xml Localization 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(" .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.PostProcess()); } // create the preprocessor and compiler Preprocessor preprocessor = new Preprocessor(); preprocessor.Message += new MessageEventHandler(this.messageHandler.Display); for (int i = 0; i < this.includeSearchPaths.Count; ++i) { preprocessor.IncludeSearchPaths.Add(this.includeSearchPaths[i]); } Compiler compiler = new Compiler(this.useSmallTables); compiler.Message += new MessageEventHandler(this.messageHandler.Display); compiler.PedanticLevel = this.pedanticLevel; compiler.SuppressValidate = this.suppressSchema; // load any extensions foreach (string extension in this.extensionList) { Type extensionType = Type.GetType(extension); if (null == extensionType) { throw new WixInvalidExtensionException(extension); } if (extensionType.IsSubclassOf(typeof(PreprocessorExtension))) { preprocessor.AddExtension((PreprocessorExtension)Activator.CreateInstance(extensionType)); } if (extensionType.IsSubclassOf(typeof(CompilerExtension))) { CompilerExtension compilerExtensionObject = Activator.CreateInstance(extensionType) as CompilerExtension; compiler.AddExtension(compilerExtensionObject); } if (!extensionType.IsSubclassOf(typeof(PreprocessorExtension)) && !extensionType.IsSubclassOf(typeof(CompilerExtension))) { throw new WixInvalidExtensionException(extension); } } // preprocess then compile each source file foreach (FileInfo sourceFile in this.sourceFiles) { currentFile = sourceFile; // point at the file we're working on in case a exception is thrown FileInfo targetFile; if (null != this.outputFile) { targetFile = this.outputFile; } else if (null != this.outputDirectory) { targetFile = new FileInfo(String.Concat(this.outputDirectory.FullName, Path.ChangeExtension(currentFile.Name, ".wixobj"))); } else { targetFile = new FileInfo(Path.ChangeExtension(currentFile.Name, ".wixobj")); } // print friendly message saying what file is being compiled Console.WriteLine(currentFile.Name); // need to clear and re-add the commandline defines for each file preprocessor.ResetParameters(); foreach (string param in this.parameters.Keys) { string name = param; if (!name.StartsWith("var.")) { name = String.Concat("var.", name); } preprocessor.Parameters.Add(name, (string)this.parameters[param]); } // preprocess the source XmlDocument sourceDocument; try { if (this.preprocessToStdout) { preprocessor.PreprocessOut = Console.Out; } else if (null != this.preprocessFile) { preprocessor.PreprocessOut = new StreamWriter(this.preprocessFile); } sourceDocument = preprocessor.Process(currentFile.FullName); } finally { if (null != preprocessor.PreprocessOut && Console.Out != preprocessor.PreprocessOut) { preprocessor.PreprocessOut.Close(); } } // if we're not actually going to compile anything, move on to the next file if (this.schemaOnly || null == sourceDocument || this.preprocessToStdout || null != this.preprocessFile) { continue; } // and now we do what we came here to do... Intermediate intermediate = compiler.Compile(sourceDocument, currentFile.FullName); // save the intermediate to disk if no errors were found for this source file if (null != intermediate) { intermediate.Save(targetFile.FullName); } // this file is was successful so clear the reference in case an exception gets thrown currentFile = null; } } catch (WixException we) { // TODO: once all WixExceptions are converted to errors, this clause // should be a no-op that just catches WixFatalErrorException's this.messageHandler.Display("candle.exe", "CNDL", we); return(1); } catch (Exception e) { this.OnMessage(WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } return(this.messageHandler.PostProcess()); }
/// <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 { // 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 (!this.fipsCompliant) { try { System.Security.Cryptography.MD5.Create(); } catch (TargetInvocationException) { this.messageHandler.Display(this, WixErrors.UseFipsArgument()); return(this.messageHandler.LastErrorNumber); } } if (0 == this.sourceFiles.Count) { this.showHelp = true; } else if (1 < this.sourceFiles.Count && null != this.outputFile) { throw new ArgumentException(CandleStrings.CannotSpecifyMoreThanOneSourceFileForSingleTargetFile, "-out"); } if (this.showLogo) { AppCommon.DisplayToolHeader(); } if (this.showHelp) { Console.WriteLine(CandleStrings.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 preprocessor and compiler Preprocessor preprocessor = new Preprocessor(); preprocessor.Message += new MessageEventHandler(this.messageHandler.Display); for (int i = 0; i < this.includeSearchPaths.Count; ++i) { preprocessor.IncludeSearchPaths.Add(this.includeSearchPaths[i]); } preprocessor.CurrentPlatform = this.platform; Compiler compiler = new Compiler(); compiler.Message += new MessageEventHandler(this.messageHandler.Display); compiler.SuppressFilesVitalByDefault = this.suppressFilesVitalByDefault; compiler.ShowPedanticMessages = this.showPedanticMessages; compiler.SuppressValidate = this.suppressSchema; compiler.CurrentPlatform = this.platform; compiler.FipsCompliant = this.fipsCompliant; // load any extensions foreach (string extension in this.extensionList) { WixExtension wixExtension = WixExtension.Load(extension); preprocessor.AddExtension(wixExtension); compiler.AddExtension(wixExtension); } // preprocess then compile each source file Dictionary <string, List <string> > sourcesForOutput = new Dictionary <string, List <string> >(StringComparer.OrdinalIgnoreCase); foreach (string sourceFileOrig in this.sourceFiles) { string sourceFile = sourceFileOrig; string targetFile = null; if (this.allowPerSourceOutputSpecification) { string[] parts = sourceFileOrig.Split(Candle.sourceOutputSeparator, 2); if (2 == parts.Length) { sourceFile = parts[0]; targetFile = parts[1]; } } string sourceFilePath = Path.GetFullPath(sourceFile); string sourceFileName = Path.GetFileName(sourceFile); if (null == targetFile) { if (null != this.outputFile) { targetFile = this.outputFile; } else if (null != this.outputDirectory) { targetFile = Path.Combine(this.outputDirectory, Path.ChangeExtension(sourceFileName, ".wixobj")); } else { targetFile = Path.ChangeExtension(sourceFileName, ".wixobj"); } } else if (!Path.IsPathRooted(targetFile) && null != this.outputDirectory) { targetFile = Path.Combine(this.outputDirectory, targetFile); } // print friendly message saying what file is being compiled Console.WriteLine(sourceFileName); // preprocess the source XmlDocument sourceDocument; try { if (this.preprocessToStdout) { preprocessor.PreprocessOut = Console.Out; } else if (null != this.preprocessFile) { preprocessor.PreprocessOut = new StreamWriter(this.preprocessFile); } sourceDocument = preprocessor.Process(sourceFilePath, this.parameters); } finally { if (null != preprocessor.PreprocessOut && Console.Out != preprocessor.PreprocessOut) { preprocessor.PreprocessOut.Close(); } } // if we're not actually going to compile anything, move on to the next file if (null == sourceDocument || this.preprocessToStdout || null != this.preprocessFile) { continue; } // and now we do what we came here to do... Intermediate intermediate = compiler.Compile(sourceDocument); // save the intermediate to disk if no errors were found for this source file if (null != intermediate) { intermediate.Save(targetFile); } // Track which source files result in a given output file, to ensure we aren't // overwriting the output. List <string> sources = null; string targetPath = Path.GetFullPath(targetFile); if (!sourcesForOutput.TryGetValue(targetPath, out sources)) { sources = new List <string>(); sourcesForOutput.Add(targetPath, sources); } sources.Add(sourceFile); } // Show an error for every output file that had more than 1 source file. foreach (KeyValuePair <string, List <string> > outputSources in sourcesForOutput) { if (1 < outputSources.Value.Count) { string sourceFiles = CompilerCore.CreateValueList(ValueListKind.None, outputSources.Value); this.messageHandler.Display(this, WixErrors.DuplicateSourcesForOutput(sourceFiles, outputSources.Key)); } } } 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); }
private void Run() { // Create the preprocessor and compiler Preprocessor preprocessor = new Preprocessor(); //preprocessor.Message += new MessageEventHandler(this.messageHandler.Display); preprocessor.CurrentPlatform = this.commandLine.Platform; foreach (string includePath in this.commandLine.IncludeSearchPaths) { preprocessor.IncludeSearchPaths.Add(includePath); } foreach (IPreprocessorExtension pe in this.preprocessorExtensions) { preprocessor.AddExtension(pe); } Compiler compiler = new Compiler(); //compiler.Message += new MessageEventHandler(this.messageHandler.Display); compiler.ShowPedanticMessages = this.commandLine.ShowPedanticMessages; compiler.CurrentPlatform = this.commandLine.Platform; foreach (IExtensionData ed in this.extensionData) { compiler.AddExtensionData(ed); } foreach (ICompilerExtension ce in this.compilerExtensions) { compiler.AddExtension(ce); } // Preprocess then compile each source file. foreach (CompileFile file in this.commandLine.Files) { // print friendly message saying what file is being compiled Console.WriteLine(file.SourcePath); // preprocess the source XDocument sourceDocument; try { if (!String.IsNullOrEmpty(this.commandLine.PreprocessFile)) { preprocessor.PreprocessOut = this.commandLine.PreprocessFile.Equals("con:", StringComparison.OrdinalIgnoreCase) ? Console.Out : new StreamWriter(this.commandLine.PreprocessFile); } sourceDocument = preprocessor.Process(file.SourcePath, this.commandLine.PreprocessorVariables); } finally { if (null != preprocessor.PreprocessOut && Console.Out != preprocessor.PreprocessOut) { preprocessor.PreprocessOut.Close(); } } // If we're not actually going to compile anything, move on to the next file. if (null == sourceDocument || !String.IsNullOrEmpty(this.commandLine.PreprocessFile)) { continue; } // and now we do what we came here to do... Intermediate intermediate = compiler.Compile(sourceDocument); // save the intermediate to disk if no errors were found for this source file if (null != intermediate) { intermediate.Save(file.OutputPath); } } }
/// <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 { // 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 (!this.fipsCompliant) { try { System.Security.Cryptography.MD5.Create(); } catch (TargetInvocationException) { this.messageHandler.Display(this, WixErrors.UseFipsArgument()); return this.messageHandler.LastErrorNumber; } } if (0 == this.sourceFiles.Count) { this.showHelp = true; } else if (1 < this.sourceFiles.Count && null != this.outputFile) { throw new ArgumentException(CandleStrings.CannotSpecifyMoreThanOneSourceFileForSingleTargetFile, "-out"); } if (this.showLogo) { AppCommon.DisplayToolHeader(); } if (this.showHelp) { Console.WriteLine(CandleStrings.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 preprocessor and compiler Preprocessor preprocessor = new Preprocessor(); preprocessor.Message += new MessageEventHandler(this.messageHandler.Display); for (int i = 0; i < this.includeSearchPaths.Count; ++i) { preprocessor.IncludeSearchPaths.Add(this.includeSearchPaths[i]); } preprocessor.CurrentPlatform = this.platform; Compiler compiler = new Compiler(); compiler.Message += new MessageEventHandler(this.messageHandler.Display); compiler.SuppressFilesVitalByDefault = this.suppressFilesVitalByDefault; compiler.ShowPedanticMessages = this.showPedanticMessages; compiler.SuppressValidate = this.suppressSchema; compiler.CurrentPlatform = this.platform; compiler.FipsCompliant = this.fipsCompliant; // load any extensions foreach (string extension in this.extensionList) { WixExtension wixExtension = WixExtension.Load(extension); preprocessor.AddExtension(wixExtension); compiler.AddExtension(wixExtension); } // preprocess then compile each source file Dictionary<string, List<string>> sourcesForOutput = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase); foreach (string sourceFileOrig in this.sourceFiles) { string sourceFile = sourceFileOrig; string targetFile = null; if (this.allowPerSourceOutputSpecification) { string[] parts = sourceFileOrig.Split(Candle.sourceOutputSeparator, 2); if (2 == parts.Length) { sourceFile = parts[0]; targetFile = parts[1]; } } string sourceFilePath = Path.GetFullPath(sourceFile); string sourceFileName = Path.GetFileName(sourceFile); if (null == targetFile) { if (null != this.outputFile) { targetFile = this.outputFile; } else if (null != this.outputDirectory) { targetFile = Path.Combine(this.outputDirectory, Path.ChangeExtension(sourceFileName, ".wixobj")); } else { targetFile = Path.ChangeExtension(sourceFileName, ".wixobj"); } } else if (!Path.IsPathRooted(targetFile) && null != this.outputDirectory) { targetFile = Path.Combine(this.outputDirectory, targetFile); } // print friendly message saying what file is being compiled Console.WriteLine(sourceFileName); // preprocess the source XmlDocument sourceDocument; try { if (this.preprocessToStdout) { preprocessor.PreprocessOut = Console.Out; } else if (null != this.preprocessFile) { preprocessor.PreprocessOut = new StreamWriter(this.preprocessFile); } sourceDocument = preprocessor.Process(sourceFilePath, this.parameters); } finally { if (null != preprocessor.PreprocessOut && Console.Out != preprocessor.PreprocessOut) { preprocessor.PreprocessOut.Close(); } } // if we're not actually going to compile anything, move on to the next file if (null == sourceDocument || this.preprocessToStdout || null != this.preprocessFile) { continue; } // and now we do what we came here to do... Intermediate intermediate = compiler.Compile(sourceDocument); // save the intermediate to disk if no errors were found for this source file if (null != intermediate) { intermediate.Save(targetFile); } // Track which source files result in a given output file, to ensure we aren't // overwriting the output. List<string> sources = null; string targetPath = Path.GetFullPath(targetFile); if (!sourcesForOutput.TryGetValue(targetPath, out sources)) { sources = new List<string>(); sourcesForOutput.Add(targetPath, sources); } sources.Add(sourceFile); } // Show an error for every output file that had more than 1 source file. foreach (KeyValuePair<string, List<string>> outputSources in sourcesForOutput) { if (1 < outputSources.Value.Count) { string sourceFiles = CompilerCore.CreateValueList(ValueListKind.None, outputSources.Value); this.messageHandler.Display(this, WixErrors.DuplicateSourcesForOutput(sourceFiles, outputSources.Key)); } } } 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 { FileInfo currentFile = null; // 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.FoundError) { return this.messageHandler.PostProcess(); } if (0 == this.sourceFiles.Count) { this.showHelp = true; } else if (1 < this.sourceFiles.Count && null != this.outputFile) { throw new ArgumentException("cannot specify more than one source file with single output file. Either specify an output directory for the -out argument by ending the argument with a '\\' or remove the -out argument to have the source files compiled to the current directory.", "-out"); } if (this.showLogo) { Assembly candleAssembly = Assembly.GetExecutingAssembly(); Console.WriteLine("Microsoft (R) Windows Installer Xml Compiler version {0}", candleAssembly.GetName().Version.ToString()); Console.WriteLine("Copyright (C) Microsoft Corporation 2003. All rights reserved."); Console.WriteLine(); } if (this.showHelp) { Console.WriteLine(" usage: candle.exe [-?] [-nologo] [-out outputFile] sourceFile [sourceFile ...]"); Console.WriteLine(); Console.WriteLine(" -d<name>=<value> define a parameter for the preprocessor"); Console.WriteLine(" -p<file> preprocess to a file (or stdout if no file supplied)"); Console.WriteLine(" -I<dir> add to include search path"); Console.WriteLine(" -nologo skip printing candle logo information"); Console.WriteLine(" -out specify output file (default: write to current directory)"); Console.WriteLine(" -pedantic:<level> pedantic checks (levels: easy, heroic, legendary)"); Console.WriteLine(" -ss suppress schema validation of documents (performance boost)"); Console.WriteLine(" -ust use small table definitions (for backwards compatiblity)"); Console.WriteLine(" -trace show source trace for errors, warnings, and verbose messages"); Console.WriteLine(" -ext extension (class, assembly), should extend CompilerExtension"); Console.WriteLine(" -zs only do validation of documents (no output)"); Console.WriteLine(" -wx treat warnings as errors"); Console.WriteLine(" -w<N> set the warning level (0: show all, 3: show none)"); Console.WriteLine(" -sw suppress all warnings (same as -w3)"); Console.WriteLine(" -sw<N> suppress warning with specific message ID"); Console.WriteLine(" -v verbose output (same as -v2)"); Console.WriteLine(" -v<N> sets the level of verbose output (0: most output, 3: none)"); 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(" .wxl - Windows installer Xml Localization 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(" .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.PostProcess(); } // create the preprocessor and compiler Preprocessor preprocessor = new Preprocessor(); preprocessor.Message += new MessageEventHandler(this.messageHandler.Display); for (int i = 0; i < this.includeSearchPaths.Count; ++i) { preprocessor.IncludeSearchPaths.Add(this.includeSearchPaths[i]); } Compiler compiler = new Compiler(this.useSmallTables); compiler.Message += new MessageEventHandler(this.messageHandler.Display); compiler.PedanticLevel = this.pedanticLevel; compiler.SuppressValidate = this.suppressSchema; // load any extensions foreach (string extension in this.extensionList) { Type extensionType = Type.GetType(extension); if (null == extensionType) { throw new WixInvalidExtensionException(extension); } if (extensionType.IsSubclassOf(typeof(PreprocessorExtension))) { preprocessor.AddExtension((PreprocessorExtension)Activator.CreateInstance(extensionType)); } if (extensionType.IsSubclassOf(typeof(CompilerExtension))) { CompilerExtension compilerExtensionObject = Activator.CreateInstance(extensionType) as CompilerExtension; compiler.AddExtension(compilerExtensionObject); } if (!extensionType.IsSubclassOf(typeof(PreprocessorExtension)) && !extensionType.IsSubclassOf(typeof(CompilerExtension))) { throw new WixInvalidExtensionException(extension); } } // preprocess then compile each source file foreach (FileInfo sourceFile in this.sourceFiles) { currentFile = sourceFile; // point at the file we're working on in case a exception is thrown FileInfo targetFile; if (null != this.outputFile) { targetFile = this.outputFile; } else if (null != this.outputDirectory) { targetFile = new FileInfo(String.Concat(this.outputDirectory.FullName, Path.ChangeExtension(currentFile.Name, ".wixobj"))); } else { targetFile = new FileInfo(Path.ChangeExtension(currentFile.Name, ".wixobj")); } // print friendly message saying what file is being compiled Console.WriteLine(currentFile.Name); // need to clear and re-add the commandline defines for each file preprocessor.ResetParameters(); foreach (string param in this.parameters.Keys) { string name = param; if (!name.StartsWith("var.")) { name = String.Concat("var.", name); } preprocessor.Parameters.Add(name, (string)this.parameters[param]); } // preprocess the source XmlDocument sourceDocument; try { if (this.preprocessToStdout) { preprocessor.PreprocessOut = Console.Out; } else if (null != this.preprocessFile) { preprocessor.PreprocessOut = new StreamWriter(this.preprocessFile); } sourceDocument = preprocessor.Process(currentFile.FullName); } finally { if (null != preprocessor.PreprocessOut && Console.Out != preprocessor.PreprocessOut) { preprocessor.PreprocessOut.Close(); } } // if we're not actually going to compile anything, move on to the next file if (this.schemaOnly || null == sourceDocument || this.preprocessToStdout || null != this.preprocessFile) { continue; } // and now we do what we came here to do... Intermediate intermediate = compiler.Compile(sourceDocument, currentFile.FullName); // save the intermediate to disk if no errors were found for this source file if (null != intermediate) { intermediate.Save(targetFile.FullName); } // this file is was successful so clear the reference in case an exception gets thrown currentFile = null; } } catch (WixException we) { // TODO: once all WixExceptions are converted to errors, this clause // should be a no-op that just catches WixFatalErrorException's this.messageHandler.Display("candle.exe", "CNDL", we); return 1; } catch (Exception e) { this.OnMessage(WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } return this.messageHandler.PostProcess(); }
/// <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 { // 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.sourceFiles.Count) { this.showHelp = true; } else if (1 < this.sourceFiles.Count && null != this.outputFile) { throw new ArgumentException("cannot specify more than one source file with single output file. Either specify an output directory for the -out argument by ending the argument with a '\\' or remove the -out argument to have the source files compiled to the current directory.", "-out"); } if (this.showLogo) { Assembly candleAssembly = Assembly.GetExecutingAssembly(); Console.WriteLine("Microsoft (R) Windows Installer Xml Compiler version {0}", candleAssembly.GetName().Version.ToString()); Console.WriteLine("Copyright (C) Microsoft Corporation 2003. All rights reserved."); Console.WriteLine(); } if (this.showHelp) { Console.WriteLine(" usage: candle.exe [-?] [-nologo] [-out outputFile] sourceFile [sourceFile ...]"); Console.WriteLine(); Console.WriteLine(" -d<name>=<value> define a parameter for the preprocessor"); Console.WriteLine(" -p<file> preprocess to a file (or stdout if no file supplied)"); Console.WriteLine(" -I<dir> add to include search path"); Console.WriteLine(" -nologo skip printing candle logo information"); Console.WriteLine(" -out specify output file (default: write to current directory)"); Console.WriteLine(" -pedantic show pedantic messages"); Console.WriteLine(" -ss suppress schema validation of documents (performance boost)"); Console.WriteLine(" -trace show source trace for errors, warnings, and verbose messages"); Console.WriteLine(" -ext extension assembly or \"class, assembly\""); Console.WriteLine(" -zs only do validation of documents (no output)"); Console.WriteLine(" -wx treat warnings as errors"); Console.WriteLine(" -sw<N> suppress warning with specific message ID"); 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(" .wxl - Windows installer Xml Localization 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 preprocessor and compiler Preprocessor preprocessor = new Preprocessor(); preprocessor.Message += new MessageEventHandler(this.messageHandler.Display); for (int i = 0; i < this.includeSearchPaths.Count; ++i) { preprocessor.IncludeSearchPaths.Add(this.includeSearchPaths[i]); } Compiler compiler = new Compiler(); compiler.Message += new MessageEventHandler(this.messageHandler.Display); compiler.ShowPedanticMessages = this.showPedanticMessages; compiler.SuppressValidate = this.suppressSchema; // load any extensions foreach (string extension in this.extensionList) { WixExtension wixExtension = WixExtension.Load(extension); preprocessor.AddExtension(wixExtension); compiler.AddExtension(wixExtension); } // preprocess then compile each source file foreach (string sourceFile in this.sourceFiles) { string sourceFileName = Path.GetFileName(sourceFile); string targetFile; if (null != this.outputFile) { targetFile = this.outputFile; } else if (null != this.outputDirectory) { targetFile = Path.Combine(this.outputDirectory, Path.ChangeExtension(sourceFileName, ".wixobj")); } else { targetFile = Path.ChangeExtension(sourceFileName, ".wixobj"); } // print friendly message saying what file is being compiled Console.WriteLine(sourceFileName); // preprocess the source XmlDocument sourceDocument; try { if (this.preprocessToStdout) { preprocessor.PreprocessOut = Console.Out; } else if (null != this.preprocessFile) { preprocessor.PreprocessOut = new StreamWriter(this.preprocessFile); } sourceDocument = preprocessor.Process(Path.GetFullPath(sourceFile), this.parameters); } finally { if (null != preprocessor.PreprocessOut && Console.Out != preprocessor.PreprocessOut) { preprocessor.PreprocessOut.Close(); } } // if we're not actually going to compile anything, move on to the next file if (this.schemaOnly || null == sourceDocument || this.preprocessToStdout || null != this.preprocessFile) { continue; } // and now we do what we came here to do... Intermediate intermediate = compiler.Compile(sourceDocument); // save the intermediate to disk if no errors were found for this source file if (null != intermediate) { intermediate.Save(targetFile); } } } 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); }