/// <summary> /// Executes a tool in-process by loading the tool assembly and invoking its entrypoint. /// </summary> /// <param name="pathToTool">Path to the tool to be executed; must be a managed executable.</param> /// <param name="responseFileCommands">Commands to be written to a response file.</param> /// <param name="commandLineCommands">Commands to be passed directly on the command-line.</param> /// <returns>The tool exit code.</returns> protected override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands) { if (this.RunAsSeparateProcess) { return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands)); } this.messageQueue = new Queue <string>(); this.messagesAvailable = new ManualResetEvent(false); this.toolExited = new ManualResetEvent(false); Util.RunningInMsBuild = true; WixToolTaskLogger logger = new WixToolTaskLogger(this.messageQueue, this.messagesAvailable); TextWriter saveConsoleOut = Console.Out; TextWriter saveConsoleError = Console.Error; Console.SetOut(logger); Console.SetError(logger); string responseFile = null; try { string responseFileSwitch; responseFile = this.GetTemporaryResponseFile(responseFileCommands, out responseFileSwitch); if (!String.IsNullOrEmpty(responseFileSwitch)) { commandLineCommands = commandLineCommands + " " + responseFileSwitch; } string[] arguments = CommandLineResponseFile.ParseArgumentsToArray(commandLineCommands); Thread toolThread = new Thread(new ParameterizedThreadStart(this.ExecuteToolThread)); toolThread.Start(new object[] { pathToTool, arguments }); this.HandleToolMessages(); if (this.exitCode == 0 && this.Log.HasLoggedErrors) { this.exitCode = -1; } return(this.exitCode); } finally { if (responseFile != null) { File.Delete(responseFile); } Console.SetOut(saveConsoleOut); Console.SetError(saveConsoleError); } }
/// <summary> /// Parse the commandline arguments. /// </summary> /// <param name="args">Commandline arguments.</param> private void ParseCommandLine(string[] args) { for (int i = 0; i < args.Length; ++i) { string arg = args[i]; if (null == arg || 0 == arg.Length) { // skip blank arguments continue; } if (1 == arg.Length) { // treat '-' and '@' as filenames when by themselves. this.inputFiles.AddRange(AppCommon.GetFiles(arg, "Source")); continue; } if ('-' == arg[0] || '/' == arg[0]) { string parameter = arg.Substring(1); if ("nologo" == parameter) { this.showLogo = false; } else if ("?" == parameter || "help" == parameter) { this.showHelp = true; return; } else { this.invalidArgs.Add(parameter); } } else if ('@' == arg[0]) { this.ParseCommandLine(CommandLineResponseFile.Parse(arg.Substring(1))); } else { this.inputFiles.AddRange(AppCommon.GetFiles(arg, "Source")); } } return; }
public static int Main(string[] args) { #if DEBUG if (args.Contains(DebugOption, StringComparer.OrdinalIgnoreCase)) { args = args.Where(arg => !string.Equals(arg, DebugOption, StringComparison.OrdinalIgnoreCase)).ToArray(); System.Diagnostics.Debugger.Launch(); } #endif #if IS_DESKTOP // Find any response files and resolve the args if (!RuntimeEnvironmentHelper.IsMono) { args = CommandLineResponseFile.ParseArgsResponseFiles(args); } #endif return(MainCore(Directory.GetCurrentDirectory(), args)); }
/// <summary> /// Parse the commandline arguments. /// </summary> /// <param name="args">Commandline arguments.</param> private void ParseCommandLine(string[] args) { for (int i = 0; i < args.Length; ++i) { string arg = args[i]; if (null == arg || 0 == arg.Length) // skip blank arguments { continue; } if (1 == arg.Length) // treat '-' and '@' as filenames when by themselves. { this.sourceFiles.AddRange(AppCommon.GetFiles(arg, "Source")); continue; } if ('-' == arg[0] || '/' == arg[0]) { string parameter = arg.Substring(1); if ("allowPerSourceOutputSpecification" == parameter) { // This is a *long* parameter name; but we want it to be painful because it's // non-standard and we don't really want to have it at all. this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("allowPerSourceOutputSpecification")); this.allowPerSourceOutputSpecification = true; } else if ('d' == parameter[0]) { if (1 >= parameter.Length || '=' == parameter[1]) { this.messageHandler.Display(this, WixErrors.InvalidVariableDefinition(arg)); return; } parameter = arg.Substring(2); string[] value = parameter.Split("=".ToCharArray(), 2); if (this.parameters.ContainsKey(value[0])) { this.messageHandler.Display(this, WixErrors.DuplicateVariableDefinition(value[0], (1 == value.Length) ? String.Empty : value[1], (string)this.parameters[value[0]])); return; } if (1 == value.Length) { this.parameters.Add(value[0], String.Empty); } else { this.parameters.Add(value[0], value[1]); } } else if ("fips" == parameter) { this.fipsCompliant = true; } else if ('I' == parameter[0]) { this.includeSearchPaths.Add(parameter.Substring(1)); } else if ("ext" == parameter) { if (!CommandLine.IsValidArg(args, ++i)) { this.messageHandler.Display(this, WixErrors.TypeSpecificationForExtensionRequired("-ext")); return; } else { this.extensionList.Add(args[i]); } } else if ("nologo" == parameter) { this.showLogo = false; } else if ("o" == parameter || "out" == parameter) { string path = CommandLine.GetFileOrDirectory(parameter, this.messageHandler, args, ++i); if (!String.IsNullOrEmpty(path)) { if (path.EndsWith("\\", StringComparison.Ordinal) || path.EndsWith("/", StringComparison.Ordinal)) { this.outputDirectory = path; } else { this.outputFile = path; } } else { return; } } else if ("pedantic" == parameter) { this.showPedanticMessages = true; } else if ("platform" == parameter || "arch" == parameter) { if ("platform" == parameter) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("platform", "arch")); } if (!CommandLine.IsValidArg(args, ++i)) { this.messageHandler.Display(this, WixErrors.InvalidPlatformParameter(parameter, String.Empty)); return; } if (String.Equals(args[i], "intel", StringComparison.OrdinalIgnoreCase) || String.Equals(args[i], "x86", StringComparison.OrdinalIgnoreCase)) { this.platform = Platform.X86; } else if (String.Equals(args[i], "x64", StringComparison.OrdinalIgnoreCase)) { this.platform = Platform.X64; } else if (String.Equals(args[i], "intel64", StringComparison.OrdinalIgnoreCase) || String.Equals(args[i], "ia64", StringComparison.OrdinalIgnoreCase)) { this.platform = Platform.IA64; } else { this.messageHandler.Display(this, WixErrors.InvalidPlatformParameter(parameter, args[i])); } } else if ('p' == parameter[0]) { String file = arg.Substring(2); this.preprocessFile = file; this.preprocessToStdout = (0 == file.Length); } else if ("sfdvital" == parameter) { this.suppressFilesVitalByDefault = true; } else if ("ss" == parameter) { this.suppressSchema = true; } else if ("swall" == parameter) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("swall", "sw")); this.messageHandler.SuppressAllWarnings = true; } else if (parameter.StartsWith("sw", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { this.messageHandler.SuppressAllWarnings = true; } else { int suppressWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= suppressWarning) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } this.messageHandler.SuppressWarningMessage(suppressWarning); } } catch (FormatException) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } catch (OverflowException) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } } else if ("wxall" == parameter) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("wxall", "wx")); this.messageHandler.WarningAsError = true; } else if (parameter.StartsWith("wx", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { this.messageHandler.WarningAsError = true; } else { int elevateWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= elevateWarning) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } this.messageHandler.ElevateWarningMessage(elevateWarning); } } catch (FormatException) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } catch (OverflowException) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } } else if ("trace" == parameter) { this.messageHandler.SourceTrace = true; } else if ("v" == parameter) { this.messageHandler.ShowVerboseMessages = true; } else if ("?" == parameter || "help" == parameter) { this.showHelp = true; return; } else { this.invalidArgs.Add(parameter); } } else if ('@' == arg[0]) { this.ParseCommandLine(CommandLineResponseFile.Parse(arg.Substring(1))); } else { string sourceArg = arg; string targetArg = null; if (this.allowPerSourceOutputSpecification) { string[] parts = arg.Split(Candle.sourceOutputSeparator, 2); if (2 == parts.Length) { sourceArg = parts[0]; targetArg = parts[1]; } } string[] files = AppCommon.GetFiles(sourceArg, "Source"); if (this.allowPerSourceOutputSpecification && null != targetArg) { // files should contain only one item! if (1 < files.Length) { string sourceList = CompilerCore.CreateValueList(ValueListKind.None, files); this.messageHandler.Display(this, WixErrors.MultipleFilesMatchedWithOutputSpecification(arg, sourceList)); } else { this.sourceFiles.Add(string.Concat(files[0], Candle.sourceOutputSeparator[0], targetArg)); } } else { this.sourceFiles.AddRange(files); } } } return; }
private void ParseCommandLine(string[] args) { for (int i = 0; i < args.Length; ++i) { string arg = args[i]; if (null == arg || 0 == arg.Length) // skip blank arguments { continue; } if (arg.Length > 1 && ('-' == arg[0] || '/' == arg[0])) { string parameter = arg.Substring(1); if (parameter.Equals("ai", StringComparison.Ordinal)) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("ai")); this.allowIdenticalRows = true; } else if (parameter.Equals("au", StringComparison.Ordinal)) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("au")); this.allowUnresolvedReferences = true; } else if (parameter.Equals("b", StringComparison.Ordinal)) { string path = CommandLine.GetDirectory(parameter, this.messageHandler, args, ++i, true); if (String.IsNullOrEmpty(path)) { return; } this.bindPaths.Add(path); } else if (parameter.Equals("binder", StringComparison.Ordinal)) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("binder")); if (!CommandLine.IsValidArg(args, ++i)) { this.messageHandler.Display(this, WixErrors.IllegalBinderClassName()); return; } this.binderClass = args[i]; } else if (parameter.Equals("bf", StringComparison.Ordinal)) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("bf")); this.bindFiles = true; } else if (parameter.StartsWith("cultures:", StringComparison.Ordinal)) { string culturesString = arg.Substring(10).ToLower(CultureInfo.InvariantCulture); // When null is used treat it as if cultures wasn't specified. // This is needed for batching over the light task when using MSBuild 2.0 which doesn't // support empty items if (culturesString.Equals("null", StringComparison.OrdinalIgnoreCase)) { this.cultures = null; } else { this.cultures = culturesString.Split(';', ','); for (int c = 0; c < this.cultures.Length; c++) { // Neutral is different from null. For neutral we still want to do WXL filtering. // Set the culture to the empty string = identifier for the invariant culture if (this.cultures[c].Equals("neutral", StringComparison.OrdinalIgnoreCase)) { this.cultures[c] = String.Empty; } } } } else if (parameter.Equals("dut", StringComparison.Ordinal)) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("dut")); this.dropUnrealTables = true; } else if (parameter.Equals("ext", StringComparison.Ordinal)) { if (!CommandLine.IsValidArg(args, ++i)) { this.messageHandler.Display(this, WixErrors.TypeSpecificationForExtensionRequired("-ext")); return; } this.extensionList.Add(args[i]); } else if (parameter.Equals("loc", StringComparison.Ordinal)) { string locFile = CommandLine.GetFile(parameter, this.messageHandler, args, ++i); if (String.IsNullOrEmpty(locFile)) { return; } this.localizationFiles.Add(locFile); } else if (parameter.Equals("nologo", StringComparison.Ordinal)) { this.showLogo = false; } else if (parameter.Equals("notidy", StringComparison.Ordinal)) { this.tidy = false; } else if ("o" == parameter || "out" == parameter) { this.outputFile = CommandLine.GetFile(parameter, this.messageHandler, args, ++i); if (String.IsNullOrEmpty(this.outputFile)) { return; } } else if (parameter.Equals("pedantic", StringComparison.Ordinal)) { this.showPedanticMessages = true; } else if (parameter.Equals("sadmin", StringComparison.Ordinal)) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("sadmin")); this.suppressAdminSequence = true; } else if (parameter.Equals("sadv", StringComparison.Ordinal)) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("sadv")); this.suppressAdvertiseSequence = true; } else if (parameter.Equals("sloc", StringComparison.Ordinal)) { this.suppressLocalization = true; } else if (parameter.Equals("sma", StringComparison.Ordinal)) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("sma")); this.suppressMsiAssemblyTable = true; } else if (parameter.Equals("ss", StringComparison.Ordinal)) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("ss")); this.suppressSchema = true; } else if (parameter.Equals("sts", StringComparison.Ordinal)) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("sts")); this.sectionIdOnRows = false; } else if (parameter.Equals("sui", StringComparison.Ordinal)) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("sui")); this.suppressUISequence = true; } else if (parameter.Equals("sv", StringComparison.Ordinal)) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("sv")); this.suppressVersionCheck = true; } else if (parameter.Equals("swall", StringComparison.Ordinal)) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("swall", "sw")); this.messageHandler.SuppressAllWarnings = true; } else if (parameter.StartsWith("sw", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { this.messageHandler.SuppressAllWarnings = true; } else { int suppressWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= suppressWarning) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } this.messageHandler.SuppressWarningMessage(suppressWarning); } } catch (FormatException) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } catch (OverflowException) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } } else if (parameter.Equals("usf", StringComparison.Ordinal)) { this.unreferencedSymbolsFile = CommandLine.GetFile(parameter, this.messageHandler, args, ++i); if (String.IsNullOrEmpty(this.unreferencedSymbolsFile)) { return; } } else if (parameter.Equals("v", StringComparison.Ordinal)) { this.messageHandler.ShowVerboseMessages = true; } else if (parameter.Equals("wxall", StringComparison.Ordinal)) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("wxall", "wx")); this.messageHandler.WarningAsError = true; } else if (parameter.StartsWith("wx", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { this.messageHandler.WarningAsError = true; } else { int elevateWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= elevateWarning) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } this.messageHandler.ElevateWarningMessage(elevateWarning); } } catch (FormatException) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } catch (OverflowException) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } } else if (parameter.Equals("xo", StringComparison.Ordinal)) { this.outputXml = true; } else if ("?" == parameter || "help" == parameter) { this.showHelp = true; return; } else { this.unparsedArgs.Add(arg); } } else if (arg.Length > 1 && '@' == arg[0]) { this.ParseCommandLine(CommandLineResponseFile.Parse(arg.Substring(1))); } else { this.unparsedArgs.Add(arg); } } if (this.bindFiles && !this.outputXml) { throw new ArgumentException(LightStrings.EXP_BindFileOptionNotApplicable); } }
/// <summary> /// Parse the commandline arguments. /// </summary> /// <param name="args">Commandline arguments.</param> private void ParseCommandLine(string[] args) { for (int i = 0; i < args.Length; ++i) { string arg = args[i]; if (null == arg || 0 == arg.Length) // skip blank arguments { continue; } if ('-' == arg[0] || '/' == arg[0]) { string parameter = arg.Substring(1); if ("nologo" == parameter) { this.showLogo = false; } else if ("o" == parameter || "out" == parameter) { this.outputFile = CommandLine.GetFile(parameter, this.messageHandler, args, ++i); if (String.IsNullOrEmpty(this.outputFile)) { return; } } else if (parameter.StartsWith("sw")) { try { int suppressWarning = Convert.ToInt32(parameter.Substring(2), CultureInfo.InvariantCulture.NumberFormat); if (0 >= suppressWarning) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(parameter.Substring(2))); } this.messageHandler.SuppressWarningMessage(suppressWarning); } catch (FormatException) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(parameter.Substring(2))); } catch (OverflowException) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(parameter.Substring(2))); } } else if ("v" == parameter) { this.messageHandler.ShowVerboseMessages = true; } else if ("wx" == parameter) { this.messageHandler.WarningAsError = true; } else if ("?" == parameter || "help" == parameter) { this.showHelp = true; } else { this.extensionOptions.Add(arg); } } else if ('@' == arg[0]) { this.ParseCommandLine(CommandLineResponseFile.Parse(arg.Substring(1))); } else if (null == this.extensionType) { this.extensionType = arg; } else { this.extensionOptions.Add(arg); } } if (null == this.extensionType || null == this.outputFile) { this.showHelp = true; } return; }
/// <summary> /// Parse the commandline arguments. /// </summary> /// <param name="args">Commandline arguments.</param> private void ParseCommandLine(string[] args) { for (int i = 0; i < args.Length; ++i) { string arg = args[i]; // skip blank arguments if (null == arg || 0 == arg.Length) { continue; } if ('-' == arg[0] || '/' == arg[0]) { string parameter = arg.Substring(1); if ("?" == parameter || "help" == parameter) { this.showHelp = true; return; } else if ("ab" == parameter) // attach container to bundle { this.bundlePath = CommandLine.GetFile(parameter, this.messageHandler, args, ++i); this.bundleWithAttachedContainerPath = CommandLine.GetFile(parameter, this.messageHandler, args, ++i); } else if ("ib" == parameter) // inscribe bundle { this.bundlePath = CommandLine.GetFile(parameter, this.messageHandler, args, ++i); } else if ("im" == parameter) // inscribe msi { this.msiPath = CommandLine.GetFile(parameter, this.messageHandler, args, ++i); } else if ("nologo" == parameter) { this.showLogo = false; } else if ("notidy" == parameter) { this.tidy = false; } else if ("o" == parameter || "out" == parameter) { this.outputPath = CommandLine.GetFileOrDirectory(parameter, this.messageHandler, args, ++i); } else if ("swall" == parameter) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("swall", "sw")); this.messageHandler.SuppressAllWarnings = true; } else if (parameter.StartsWith("sw", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { this.messageHandler.SuppressAllWarnings = true; } else { int suppressWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= suppressWarning) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } this.messageHandler.SuppressWarningMessage(suppressWarning); } } catch (FormatException) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } catch (OverflowException) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } } else if ("v" == parameter) { this.messageHandler.ShowVerboseMessages = true; } else if ("wxall" == parameter) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("wxall", "wx")); this.messageHandler.WarningAsError = true; } else if (parameter.StartsWith("wx", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { this.messageHandler.WarningAsError = true; } else { int elevateWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= elevateWarning) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } this.messageHandler.ElevateWarningMessage(elevateWarning); } } catch (FormatException) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } catch (OverflowException) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } } else { this.invalidArgs.Add(parameter); } } else if ('@' == arg[0]) { this.ParseCommandLine(CommandLineResponseFile.Parse(arg.Substring(1))); } else { this.invalidArgs.Add(arg); } } }
/// <summary> /// Parse the commandline arguments. /// </summary> /// <param name="args">Commandline arguments.</param> public string[] Parse(string[] args) { List <string> unprocessed = new List <string>(); for (int i = 0; i < args.Length; ++i) { string arg = args[i]; if (String.IsNullOrEmpty(arg)) // skip blank arguments { continue; } if (1 == arg.Length) // treat '-' and '@' as filenames when by themselves. { unprocessed.Add(arg); } else if ('-' == arg[0] || '/' == arg[0]) { string parameter = arg.Substring(1); if ("b" == parameter) { BindPath bindPath = CommandLine.GetBindPath(parameter, args, ++i); if (null == bindPath) { break; } this.BindPaths.Add(bindPath); } else if ("bf" == parameter) { this.BindFiles = true; } else if ("ext" == parameter) { if (!CommandLine.IsValidArg(args, ++i)) { Messaging.Instance.OnMessage(WixErrors.TypeSpecificationForExtensionRequired("-ext")); break; } this.Extensions.Add(args[i]); } else if ("loc" == parameter) { string locFile = CommandLine.GetFile(parameter, args, ++i); if (String.IsNullOrEmpty(locFile)) { break; } this.LocalizationFiles.Add(locFile); } else if ("nologo" == parameter) { this.ShowLogo = false; } else if ("o" == parameter || "out" == parameter) { this.OutputFile = CommandLine.GetFile(parameter, args, ++i); if (String.IsNullOrEmpty(this.OutputFile)) { break; } } else if ("pedantic" == parameter) { this.ShowPedanticMessages = true; } else if ("sv" == parameter) { this.SuppressVersionCheck = true; } else if (parameter.StartsWith("sw", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); if (0 == paramArg.Length) { Messaging.Instance.SuppressAllWarnings = true; } else { int suppressWarning = 0; if (!Int32.TryParse(paramArg, out suppressWarning) || 0 >= suppressWarning) { Messaging.Instance.OnMessage(WixErrors.IllegalSuppressWarningId(paramArg)); } else { Messaging.Instance.SuppressWarningMessage(suppressWarning); } } } else if (parameter.StartsWith("wx", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); if (0 == paramArg.Length) { Messaging.Instance.WarningsAsError = true; } else { int elevateWarning = 0; if (!Int32.TryParse(paramArg, out elevateWarning) || 0 >= elevateWarning) { Messaging.Instance.OnMessage(WixErrors.IllegalWarningIdAsError(paramArg)); } else { Messaging.Instance.ElevateWarningMessage(elevateWarning); } } } else if ("v" == parameter) { Messaging.Instance.ShowVerboseMessages = true; } else if ("?" == parameter || "help" == parameter) { this.ShowHelp = true; break; } else { unprocessed.Add(arg); } } else if ('@' == arg[0]) { string[] parsedArgs = CommandLineResponseFile.Parse(arg.Substring(1)); string[] unparsedArgs = this.Parse(parsedArgs); unprocessed.AddRange(unparsedArgs); } else { unprocessed.Add(arg); } } return(unprocessed.ToArray()); }
/// <summary> /// Parse the commandline arguments. /// </summary> /// <param name="args">Commandline arguments.</param> private void ParseCommandLine(string[] args) { for (int i = 0; i < args.Length; ++i) { string arg = args[i]; if (null == arg || 0 == arg.Length) { // skip blank arguments continue; } if (1 == arg.Length) { // treat '-' and '@' as filenames when by themselves. this.inputFiles.AddRange(AppCommon.GetFiles(arg, "Source")); continue; } if ('-' == arg[0] || '/' == arg[0]) { string parameter = arg.Substring(1); if ("ext" == parameter) { if (!CommandLine.IsValidArg(args, ++i)) { this.messageHandler.Display(this, WixErrors.TypeSpecificationForExtensionRequired("-ext")); return; } this.extensionList.Add(args[i]); } else if ("nologo" == parameter) { this.showLogo = false; } else if ("o" == parameter || "out" == parameter) { string path = CommandLine.GetFileOrDirectory(parameter, this.messageHandler, args, ++i); if (String.IsNullOrEmpty(path)) { return; } else { this.outputFile = path; } } else if ("v" == parameter) { this.messageHandler.ShowVerboseMessages = true; } else if ("?" == parameter || "help" == parameter) { this.showHelp = true; return; } else { this.invalidArgs.Add(parameter); } } else if ('@' == arg[0]) { this.ParseCommandLine(CommandLineResponseFile.Parse(arg.Substring(1))); } else { this.inputFiles.AddRange(AppCommon.GetFiles(arg, "Source")); } } return; }
private static string[] ParseArgs(string[] args) { return(CommandLineResponseFile.ParseArgsResponseFiles(args)); }
/// <summary> /// Parse the commandline arguments. /// </summary> /// <param name="args">Commandline arguments.</param> public string[] Parse(string[] args) { List <string> unprocessed = new List <string>(); for (int i = 0; i < args.Length; ++i) { string arg = args[i]; if (String.IsNullOrEmpty(arg)) // skip blank arguments { continue; } if (1 == arg.Length) // treat '-' and '@' as filenames when by themselves. { unprocessed.Add(arg); } else if ('-' == arg[0] || '/' == arg[0]) { string parameter = arg.Substring(1); if ("bt" == parameter) { BindPath bindPath = CommandLine.GetBindPath(parameter, args, ++i); if (null == bindPath) { break; } this.TargetBindPaths.Add(bindPath); } else if ("bu" == parameter) { BindPath bindPath = CommandLine.GetBindPath(parameter, args, ++i); if (null == bindPath) { break; } this.UpdatedBindPaths.Add(bindPath); } else if (parameter.Equals("cc", StringComparison.Ordinal)) { this.CabCachePath = CommandLine.GetDirectory(parameter, args, ++i); if (String.IsNullOrEmpty(this.CabCachePath)) { break; } } else if (parameter.Equals("delta", StringComparison.Ordinal)) { this.Delta = true; } else if (parameter.Equals("ext", StringComparison.Ordinal)) { if (!CommandLine.IsValidArg(args, ++i)) { Messaging.Instance.OnMessage(WixErrors.TypeSpecificationForExtensionRequired("-ext")); break; } this.Extensions.Add(args[i]); } else if ("nologo" == parameter) { this.ShowLogo = false; } else if ("notidy" == parameter) { this.Tidy = false; } else if ("o" == parameter || "out" == parameter) { this.OutputFile = CommandLine.GetFile(parameter, args, ++i); if (String.IsNullOrEmpty(this.OutputFile)) { break; } } else if (parameter.Equals("pdbout", StringComparison.Ordinal)) { this.PdbFile = CommandLine.GetFile(parameter, args, ++i); if (String.IsNullOrEmpty(this.PdbFile)) { break; } } else if (parameter.Equals("reusecab", StringComparison.Ordinal)) { Messaging.Instance.OnMessage(WixWarnings.DeprecatedCommandLineSwitch(arg, "-cc")); } else if (parameter.Equals("spdb", StringComparison.Ordinal)) { this.SuppressWixPdb = true; } else if (parameter.Equals("sacl", StringComparison.Ordinal)) { this.SuppressAclReset = true; } else if (parameter.Equals("t", StringComparison.Ordinal)) { string baseline; string transformPath; if (!CommandLine.IsValidArg(args, ++i)) { Messaging.Instance.OnMessage(WixErrors.BaselineRequired()); break; } baseline = args[i]; transformPath = CommandLine.GetFile(parameter, args, ++i); if (String.IsNullOrEmpty(transformPath)) { break; } // Verify the transform hasn't been added already. if (this.PatchTransforms.Any(t => t.TransformPath.Equals(transformPath, StringComparison.OrdinalIgnoreCase))) { Messaging.Instance.OnMessage(WixErrors.DuplicateTransform(transformPath)); break; } this.PatchTransforms.Add(new PatchTransform(transformPath, baseline)); } else if (parameter.StartsWith("sw", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); if (0 == paramArg.Length) { Messaging.Instance.SuppressAllWarnings = true; } else { int suppressWarning = 0; if (!Int32.TryParse(paramArg, out suppressWarning) || 0 >= suppressWarning) { Messaging.Instance.OnMessage(WixErrors.IllegalSuppressWarningId(paramArg)); } else { Messaging.Instance.SuppressWarningMessage(suppressWarning); } } } else if (parameter.StartsWith("wx", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); if (0 == paramArg.Length) { Messaging.Instance.WarningsAsError = true; } else { int elevateWarning = 0; if (!Int32.TryParse(paramArg, out elevateWarning) || 0 >= elevateWarning) { Messaging.Instance.OnMessage(WixErrors.IllegalWarningIdAsError(paramArg)); } else { Messaging.Instance.ElevateWarningMessage(elevateWarning); } } } else if ("v" == parameter) { Messaging.Instance.ShowVerboseMessages = true; } else if ("?" == parameter || "help" == parameter) { this.ShowHelp = true; break; } else { unprocessed.Add(arg); } } else if ('@' == arg[0]) { string[] parsedArgs = CommandLineResponseFile.Parse(arg.Substring(1)); string[] unparsedArgs = this.Parse(parsedArgs); unprocessed.AddRange(unparsedArgs); } else { unprocessed.Add(arg); } } return(unprocessed.ToArray()); }
/// <summary> /// Parse the commandline arguments. /// </summary> /// <param name="args">Commandline arguments.</param> public string[] Parse(string[] args) { List <string> unprocessed = new List <string>(); for (int i = 0; i < args.Length; ++i) { string arg = args[i]; if (String.IsNullOrEmpty(arg)) // skip blank arguments { continue; } if (1 == arg.Length) // treat '-' and '@' as filenames when by themselves. { unprocessed.Add(arg); } else if ('-' == arg[0] || '/' == arg[0]) { string parameter = arg.Substring(1); if (parameter.Equals("b", StringComparison.Ordinal)) { BindPath bindPath = CommandLine.GetBindPath(parameter, args, ++i); if (null == bindPath) { break; } this.BindPaths.Add(bindPath); } else if (parameter.StartsWith("cultures:", StringComparison.Ordinal)) { string culturesString = arg.Substring(10).ToLower(CultureInfo.InvariantCulture); // When null is used treat it as if cultures wasn't specified. // This is needed for batching over the light task when using MSBuild which doesn't // support empty items if (culturesString.Equals("null", StringComparison.OrdinalIgnoreCase)) { this.Cultures = null; } else { this.Cultures = culturesString.Split(';', ','); for (int c = 0; c < this.Cultures.Length; ++c) { // Neutral is different from null. For neutral we still want to do WXL filtering. // Set the culture to the empty string = identifier for the invariant culture if (this.Cultures[c].Equals("neutral", StringComparison.OrdinalIgnoreCase)) { this.Cultures[c] = String.Empty; } } } } else if (parameter.StartsWith("dcl:", StringComparison.Ordinal)) { string defaultCompressionLevel = arg.Substring(5); if (String.IsNullOrEmpty(defaultCompressionLevel)) { break; } this.DefaultCompressionLevel = WixCreateCab.CompressionLevelFromString(defaultCompressionLevel); } else if (parameter.StartsWith("d", StringComparison.Ordinal)) { parameter = arg.Substring(2); string[] value = parameter.Split("=".ToCharArray(), 2); string preexisting; if (1 == value.Length) { Messaging.Instance.OnMessage(WixErrors.ExpectedWixVariableValue(value[0])); } else if (this.Variables.TryGetValue(value[0], out preexisting)) { Messaging.Instance.OnMessage(WixErrors.WixVariableCollision(null, value[0])); } else { this.Variables.Add(value[0], value[1]); } } else if (parameter.Equals("ext", StringComparison.Ordinal)) { if (!CommandLine.IsValidArg(args, ++i)) { Messaging.Instance.OnMessage(WixErrors.TypeSpecificationForExtensionRequired("-ext")); break; } this.Extensions.Add(args[i]); } else if (parameter.Equals("loc", StringComparison.Ordinal)) { string locFile = CommandLine.GetFile(parameter, args, ++i); if (String.IsNullOrEmpty(locFile)) { break; } this.LocalizationFiles.Add(locFile); } else if (parameter.Equals("nologo", StringComparison.Ordinal)) { this.ShowLogo = false; } else if (parameter.Equals("notidy", StringComparison.Ordinal)) { this.Tidy = false; } else if ("o" == parameter || "out" == parameter) { this.OutputFile = CommandLine.GetFile(parameter, args, ++i); if (String.IsNullOrEmpty(this.OutputFile)) { break; } } else if (parameter.Equals("pedantic", StringComparison.Ordinal)) { this.ShowPedanticMessages = true; } else if (parameter.Equals("sloc", StringComparison.Ordinal)) { this.SuppressLocalization = true; } else if (parameter.Equals("usf", StringComparison.Ordinal)) { this.UnreferencedSymbolsFile = CommandLine.GetFile(parameter, args, ++i); if (String.IsNullOrEmpty(this.UnreferencedSymbolsFile)) { break; } } else if (parameter.Equals("xo", StringComparison.Ordinal)) { this.OutputXml = true; } else if (parameter.Equals("cc", StringComparison.Ordinal)) { this.CabCachePath = CommandLine.GetDirectory(parameter, args, ++i); if (String.IsNullOrEmpty(this.CabCachePath)) { break; } } else if (parameter.Equals("ct", StringComparison.Ordinal)) { if (!CommandLine.IsValidArg(args, ++i)) { Messaging.Instance.OnMessage(WixErrors.IllegalCabbingThreadCount(String.Empty)); break; } int ct = 0; if (!Int32.TryParse(args[i], out ct) || 0 >= ct) { Messaging.Instance.OnMessage(WixErrors.IllegalCabbingThreadCount(args[i])); break; } this.CabbingThreadCount = ct; Messaging.Instance.OnMessage(WixVerboses.SetCabbingThreadCount(this.CabbingThreadCount.ToString())); } else if (parameter.Equals("cub", StringComparison.Ordinal)) { string cubeFile = CommandLine.GetFile(parameter, args, ++i); if (String.IsNullOrEmpty(cubeFile)) { break; } this.CubeFiles.Add(cubeFile); } else if (parameter.Equals("eav", StringComparison.Ordinal)) { Messaging.Instance.OnMessage(WixWarnings.DeprecatedCommandLineSwitch(arg)); } else if (parameter.StartsWith("ice:", StringComparison.Ordinal)) { this.Ices.Add(parameter.Substring(4)); } else if (parameter.Equals("contentsfile", StringComparison.Ordinal)) { this.ContentsFile = CommandLine.GetFile(parameter, args, ++i); if (String.IsNullOrEmpty(this.ContentsFile)) { break; } } else if (parameter.Equals("outputsfile", StringComparison.Ordinal)) { this.OutputsFile = CommandLine.GetFile(parameter, args, ++i); if (String.IsNullOrEmpty(this.OutputsFile)) { break; } } else if (parameter.Equals("builtoutputsfile", StringComparison.Ordinal)) { this.BuiltOutputsFile = CommandLine.GetFile(parameter, args, ++i); if (String.IsNullOrEmpty(this.BuiltOutputsFile)) { break; } } else if (parameter.Equals("wixprojectfile", StringComparison.Ordinal)) { this.WixprojectFile = CommandLine.GetFile(parameter, args, ++i); if (String.IsNullOrEmpty(this.WixprojectFile)) { break; } } else if (parameter.Equals("pdbout", StringComparison.Ordinal)) { this.PdbFile = CommandLine.GetFile(parameter, args, ++i); if (String.IsNullOrEmpty(this.PdbFile)) { break; } } else if (parameter.Equals("reusecab", StringComparison.Ordinal)) { Messaging.Instance.OnMessage(WixWarnings.DeprecatedCommandLineSwitch(arg, "-cc")); } else if (parameter.StartsWith("sice:", StringComparison.Ordinal)) { this.SuppressIces.Add(parameter.Substring(5)); } else if (parameter.Equals("sl", StringComparison.Ordinal)) { this.SuppressLayout = true; } else if (parameter.Equals("spdb", StringComparison.Ordinal)) { this.SuppressWixPdb = true; } else if (parameter.Equals("sacl", StringComparison.Ordinal)) { this.SuppressAclReset = true; } else if (parameter.Equals("sval", StringComparison.Ordinal)) { this.SuppressValidation = true; } else if ("sv" == parameter) { this.SuppressVersionCheck = true; } else if (parameter.StartsWith("sw", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); if (0 == paramArg.Length) { Messaging.Instance.SuppressAllWarnings = true; } else { int suppressWarning = 0; if (!Int32.TryParse(paramArg, out suppressWarning) || 0 >= suppressWarning) { Messaging.Instance.OnMessage(WixErrors.IllegalSuppressWarningId(paramArg)); } else { Messaging.Instance.SuppressWarningMessage(suppressWarning); } } } else if (parameter.StartsWith("wx", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); if (0 == paramArg.Length) { Messaging.Instance.WarningsAsError = true; } else { int elevateWarning = 0; if (!Int32.TryParse(paramArg, out elevateWarning) || 0 >= elevateWarning) { Messaging.Instance.OnMessage(WixErrors.IllegalWarningIdAsError(paramArg)); } else { Messaging.Instance.ElevateWarningMessage(elevateWarning); } } } else if ("v" == parameter) { Messaging.Instance.ShowVerboseMessages = true; } else if ("?" == parameter || "help" == parameter) { this.ShowHelp = true; break; } else { unprocessed.Add(arg); } } else if ('@' == arg[0]) { string[] parsedArgs = CommandLineResponseFile.Parse(arg.Substring(1)); string[] unparsedArgs = this.Parse(parsedArgs); unprocessed.AddRange(unparsedArgs); } else { unprocessed.Add(arg); } } return(unprocessed.ToArray()); }
/// <summary> /// Parse the commandline arguments. /// </summary> /// <param name="args">Commandline arguments.</param> private void ParseCommandLine(string[] args) { for (int i = 0; i < args.Length; ++i) { string arg = args[i]; if (null == arg || 0 == arg.Length) // skip blank arguments { continue; } if ('-' == arg[0] || '/' == arg[0]) { string parameter = arg.Substring(1); if ("aet" == parameter) { this.allowEmptyTransforms = true; } else if ("bt" == parameter) { string path = CommandLine.GetDirectory(parameter, this.messageHandler, args, ++i, true); if (String.IsNullOrEmpty(path)) { return; } if (-1 == path.IndexOf('=')) { this.targetSourcePaths.Add(path); } else { string[] namedPair = path.Split('='); this.targetNamedBindPaths.Add(namedPair[0], namedPair[1]); } } else if ("bu" == parameter) { string path = CommandLine.GetDirectory(parameter, this.messageHandler, args, ++i, true); if (String.IsNullOrEmpty(path)) { return; } if (-1 == path.IndexOf('=')) { this.updatedSourcePaths.Add(path); } else { string[] namedPair = path.Split('='); this.updatedNamedBindPaths.Add(namedPair[0], namedPair[1]); } } else if ("cc" == parameter) { this.cabCachePath = CommandLine.GetDirectory(parameter, this.messageHandler, args, ++i); if (String.IsNullOrEmpty(this.cabCachePath)) { return; } } else if ("delta" == parameter) { this.delta = true; } else if ("ext" == parameter) { if (!CommandLine.IsValidArg(args, ++i)) { this.messageHandler.Display(this, WixErrors.TypeSpecificationForExtensionRequired("-ext")); return; } this.extensions.Add(args[i]); } else if ("fv" == parameter) { this.setAssemblyFileVersions = true; } else if ("nologo" == parameter) { this.showLogo = false; } else if ("notidy" == parameter) { this.tidy = false; } else if ("swall" == parameter) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("swall", "sw")); this.messageHandler.SuppressAllWarnings = true; } else if (parameter.StartsWith("sw", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { this.messageHandler.SuppressAllWarnings = true; } else { int suppressWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= suppressWarning) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } this.messageHandler.SuppressWarningMessage(suppressWarning); } } catch (FormatException) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } catch (OverflowException) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } } else if ("wxall" == parameter) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("wxall", "wx")); this.messageHandler.WarningAsError = true; } else if (parameter.StartsWith("wx", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { this.messageHandler.WarningAsError = true; } else { int elevateWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= elevateWarning) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } this.messageHandler.ElevateWarningMessage(elevateWarning); } } catch (FormatException) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } catch (OverflowException) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } } else if ("o" == parameter || "out" == parameter) { this.outputFile = CommandLine.GetFile(parameter, this.messageHandler, args, ++i); if (String.IsNullOrEmpty(this.outputFile)) { return; } } else if ("pdbout" == parameter) { this.pdbFile = CommandLine.GetFile(parameter, this.messageHandler, args, ++i); if (String.IsNullOrEmpty(this.pdbFile)) { return; } } else if ("reusecab" == parameter) { this.reuseCabinets = true; } else if ("sa" == parameter) { this.suppressAssemblies = true; } else if ("sf" == parameter) { this.suppressFiles = true; } else if ("sh" == parameter) { this.suppressFileHashAndInfo = true; } else if ("spdb" == parameter) { this.suppressWixPdb = true; } else if ("t" == parameter) { string transform = null; string baseline = null; if (!CommandLine.IsValidArg(args, ++i)) { this.messageHandler.Display(this, WixErrors.BaselineRequired()); return; } baseline = args[i]; transform = CommandLine.GetFile(parameter, this.messageHandler, args, ++i); if (String.IsNullOrEmpty(transform)) { return; } // Verify the transform hasnt already been added. if (this.inputTransforms.ContainsKey(transform)) { this.messageHandler.Display(this, WixErrors.DuplicateTransform(transform)); return; } this.inputTransforms.Add(transform, baseline); this.inputTransformsOrdered.Add(transform); } else if ("v" == parameter) { this.messageHandler.ShowVerboseMessages = true; } else if ("?" == parameter || "help" == parameter) { this.showHelp = true; return; } else { this.unparsedArgs.Add(arg); } } else if ('@' == arg[0]) { this.ParseCommandLine(CommandLineResponseFile.Parse(arg.Substring(1))); } else { if (null == this.inputFile) { this.inputFile = CommandLine.VerifyPath(this.messageHandler, arg); if (String.IsNullOrEmpty(this.inputFile)) { return; } } else { this.unparsedArgs.Add(arg); } } } }
/// <summary> /// Parse the commandline arguments. /// </summary> /// <param name="args">Commandline arguments.</param> public string[] Parse(string[] args) { List <string> unprocessed = new List <string>(); for (int i = 0; i < args.Length; ++i) { string arg = args[i]; if (String.IsNullOrEmpty(arg)) // skip blank arguments { continue; } if (1 == arg.Length) // treat '-' and '@' as filenames when by themselves. { unprocessed.Add(arg); } else if ('-' == arg[0] || '/' == arg[0]) { string parameter = arg.Substring(1); if ("nologo" == parameter) { this.ShowLogo = false; } else if ("o" == parameter || "out" == parameter) { string path = CommandLine.GetFile(parameter, args, ++i); if (!String.IsNullOrEmpty(path)) { this.OutputFile = path; } else { break; } } else if ("?" == parameter || "help" == parameter) { this.ShowHelp = true; break; } else if ("header" == parameter) { if (CommandLine.IsValidArg(args, ++i)) { this.HeaderName = args[i]; } } else if ("prefix" == parameter) { if (CommandLine.IsValidArg(args, ++i)) { this.Prefix = args[i]; } } else { unprocessed.Add(arg); } } else if ('@' == arg[0]) { string[] parsedArgs = CommandLineResponseFile.Parse(arg.Substring(1)); string[] unparsedArgs = this.Parse(parsedArgs); unprocessed.AddRange(unparsedArgs); } else { var files = CommandLine.GetFiles(arg, "Source"); if (1 == files.Length) { this.InputFile = files[0]; } else { unprocessed.AddRange(files); } } } if (String.IsNullOrEmpty(this.InputFile)) { this.ShowHelp = true; } return(unprocessed.ToArray()); }
/// <summary> /// Parse the commandline arguments. /// </summary> /// <param name="args">The commandline arguments.</param> private void ParseCommandLine(string[] args) { this.showHelp = 0 == args.Length; for (int i = 0; i < args.Length; ++i) { string arg = args[i]; if (String.IsNullOrEmpty(arg)) // skip blank arguments { continue; } if ('-' == arg[0] || '/' == arg[0]) { string parameter = arg.Substring(1); switch (parameter) { case "?": this.showHelp = true; break; case "f": this.fixErrors = true; break; case "nologo": this.showLogo = false; break; case "s": this.subDirectories = true; break; default: // other parameters if (parameter.StartsWith("set1", StringComparison.Ordinal)) { this.settingsFile1 = parameter.Substring(4); } else if (parameter.StartsWith("set2", StringComparison.Ordinal)) { this.settingsFile2 = parameter.Substring(4); } else if (parameter.StartsWith("indent:", StringComparison.Ordinal)) { try { this.indentationAmount = Int32.Parse(parameter.Substring(7), CultureInfo.InvariantCulture); } catch { throw new ArgumentException("Invalid numeric argument.", parameter); } } else { throw new ArgumentException("Invalid argument.", parameter); } break; } } else if ('@' == arg[0]) { this.ParseCommandLine(CommandLineResponseFile.Parse(arg.Substring(1))); } else { this.searchPatterns.Add(arg); } } }
/// <summary> /// Parse the commandline arguments. /// </summary> /// <param name="args">Commandline arguments.</param> private void ParseCommandLine(string[] args) { for (int i = 0; i < args.Length; ++i) { string arg = args[i]; // skip blank arguments if (null == arg || 0 == arg.Length) { continue; } if ('-' == arg[0] || '/' == arg[0]) { string parameter = arg.Substring(1); if ("cub" == parameter) { string cubeFile = CommandLine.GetFile(parameter, this.messageHandler, args, ++i); if (String.IsNullOrEmpty(cubeFile)) { return; } this.validator.AddCubeFile(cubeFile); } else if ("ext" == parameter) { if (!CommandLine.IsValidArg(args, ++i)) { this.messageHandler.Display(this, WixErrors.TypeSpecificationForExtensionRequired("-ext")); return; } this.extensionList.Add(args[i]); } else if (parameter.StartsWith("ice:")) { this.ices.Add(parameter.Substring(4)); } else if ("pdb" == parameter) { this.pdbPath = CommandLine.GetFile(parameter, this.messageHandler, args, ++i); if (String.IsNullOrEmpty(this.pdbPath)) { return; } } else if ("nodefault" == parameter) { this.addDefault = false; } else if ("nologo" == parameter) { this.showLogo = false; } else if ("notidy" == parameter) { this.tidy = false; } else if (parameter.StartsWith("sice:")) { this.suppressICEs.Add(parameter.Substring(5)); } else if ("swall" == parameter) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("swall", "sw")); this.messageHandler.SuppressAllWarnings = true; } else if (parameter.StartsWith("sw")) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { this.messageHandler.SuppressAllWarnings = true; } else { int suppressWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= suppressWarning) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } this.messageHandler.SuppressWarningMessage(suppressWarning); } } catch (FormatException) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } catch (OverflowException) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } } else if ("wxall" == parameter) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("wxall", "wx")); this.messageHandler.WarningAsError = true; } else if (parameter.StartsWith("wx")) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { this.messageHandler.WarningAsError = true; } else { int elevateWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= elevateWarning) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } this.messageHandler.ElevateWarningMessage(elevateWarning); } } catch (FormatException) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } catch (OverflowException) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } } else if ("v" == parameter) { this.messageHandler.ShowVerboseMessages = true; } else if ("?" == parameter || "help" == parameter) { this.showHelp = true; return; } else { this.invalidArgs.Add(parameter); } } else if ('@' == arg[0]) { this.ParseCommandLine(CommandLineResponseFile.Parse(arg.Substring(1))); } else { // Verify the file extension is an expected value if (IsValidFileExtension(arg)) { this.inputFiles.AddRange(AppCommon.GetFiles(arg, "Source")); } } } }
/// <summary> /// Parse the commandline arguments. /// </summary> /// <param name="args">Commandline arguments.</param> private void ParseCommandLine(string[] args) { for (int i = 0; i < args.Length; ++i) { string arg = args[i]; if (String.Equals(arg.Substring(1), "?", StringComparison.OrdinalIgnoreCase) || String.Equals(arg.Substring(1), "help", StringComparison.OrdinalIgnoreCase)) { this.showHelp = true; return; } else if (0 == i) { if ('@' == arg[0]) { this.ParseCommandLine(CommandLineResponseFile.Parse(arg.Substring(1))); } else { if (!arg.StartsWith("-")) { this.extensionType = arg; } else { Messaging.Instance.OnMessage(WixErrors.HarvestTypeNotFound(arg)); } } } else if (1 == i) { this.extensionArgument = arg; } else if ('-' == arg[0] || '/' == arg[0]) { string parameter = arg.Substring(1); if ("nologo" == parameter) { this.showLogo = false; } else if ("o" == parameter || "out" == parameter) { this.outputFile = CommandLine.GetFile(parameter, args, ++i); if (String.IsNullOrEmpty(this.outputFile)) { return; } } else if ("swall" == parameter) { Messaging.Instance.OnMessage(WixWarnings.DeprecatedCommandLineSwitch("swall", "sw")); Messaging.Instance.SuppressAllWarnings = true; } else if (parameter.StartsWith("sw")) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { Messaging.Instance.SuppressAllWarnings = true; } else { int suppressWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= suppressWarning) { Messaging.Instance.OnMessage(WixErrors.IllegalSuppressWarningId(paramArg)); } Messaging.Instance.SuppressWarningMessage(suppressWarning); } } catch (FormatException) { Messaging.Instance.OnMessage(WixErrors.IllegalSuppressWarningId(paramArg)); } catch (OverflowException) { Messaging.Instance.OnMessage(WixErrors.IllegalSuppressWarningId(paramArg)); } } else if ("wxall" == parameter) { Messaging.Instance.OnMessage(WixWarnings.DeprecatedCommandLineSwitch("wxall", "wx")); Messaging.Instance.WarningsAsError = true; } else if (parameter.StartsWith("wx")) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { Messaging.Instance.WarningsAsError = true; } else { int elevateWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= elevateWarning) { Messaging.Instance.OnMessage(WixErrors.IllegalWarningIdAsError(paramArg)); } Messaging.Instance.ElevateWarningMessage(elevateWarning); } } catch (FormatException) { Messaging.Instance.OnMessage(WixErrors.IllegalWarningIdAsError(paramArg)); } catch (OverflowException) { Messaging.Instance.OnMessage(WixErrors.IllegalWarningIdAsError(paramArg)); } } else if ("v" == parameter) { Messaging.Instance.ShowVerboseMessages = true; } else if ("ext" == parameter) { if (!CommandLine.IsValidArg(args, ++i)) { Messaging.Instance.OnMessage(WixErrors.TypeSpecificationForExtensionRequired("-ext")); } else { this.LoadExtension(args[i]); } } else if ("indent" == parameter) { try { this.indent = Int32.Parse(args[++i], CultureInfo.InvariantCulture); } catch { throw new ArgumentException("Invalid numeric argument.", parameter); } } } if ('@' != arg[0]) { this.extensionOptions.Add(arg); } } if (String.IsNullOrEmpty(this.extensionType)) { this.showHelp = true; } else if (String.IsNullOrEmpty(this.extensionArgument)) { Messaging.Instance.OnMessage(WixErrors.HarvestSourceNotSpecified()); } else if (String.IsNullOrEmpty(this.outputFile)) { Messaging.Instance.OnMessage(WixErrors.OutputTargetNotSpecified()); } return; }
/// <summary> /// Parse the commandline arguments. /// </summary> /// <param name="args">Commandline arguments.</param> private void ParseCommandLine(string[] args) { for (int i = 0; i < args.Length; ++i) { string arg = args[i]; if (null == arg || 0 == arg.Length) // skip blank arguments { continue; } if ('-' == arg[0] || '/' == arg[0]) { string parameter = arg.Substring(1); if ("b" == parameter) { string bindPath = CommandLine.GetDirectory(parameter, this.messageHandler, args, ++i, true); if (String.IsNullOrEmpty(bindPath)) { return; } this.bindPaths.Add(bindPath); } else if ("bf" == parameter) { this.bindFiles = true; } else if ("ext" == parameter) { if (!CommandLine.IsValidArg(args, ++i)) { this.messageHandler.Display(this, WixErrors.TypeSpecificationForExtensionRequired("-ext")); return; } this.extensionList.Add(args[i]); } else if ("loc" == parameter) { string locFile = CommandLine.GetFile(parameter, this.messageHandler, args, ++i); if (String.IsNullOrEmpty(locFile)) { return; } this.localizationFiles.Add(locFile); } else if ("nologo" == parameter) { this.showLogo = false; } else if ("o" == parameter || "out" == parameter) { this.outputFile = CommandLine.GetFile(parameter, this.messageHandler, args, ++i); if (String.IsNullOrEmpty(this.outputFile)) { return; } } else if ("pedantic" == parameter) { this.showPedanticMessages = true; } else if ("ss" == parameter) { this.suppressSchema = true; } else if ("sv" == parameter) { this.suppressVersionCheck = true; } else if ("swall" == parameter) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("swall", "sw")); this.messageHandler.SuppressAllWarnings = true; } else if (parameter.StartsWith("sw", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { this.messageHandler.SuppressAllWarnings = true; } else { int suppressWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= suppressWarning) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } this.messageHandler.SuppressWarningMessage(suppressWarning); } } catch (FormatException) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } catch (OverflowException) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } } else if ("wxall" == parameter) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("wxall", "wx")); this.messageHandler.WarningAsError = true; } else if (parameter.StartsWith("wx", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { this.messageHandler.WarningAsError = true; } else { int elevateWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= elevateWarning) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } this.messageHandler.ElevateWarningMessage(elevateWarning); } } catch (FormatException) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } catch (OverflowException) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } } else if ("v" == parameter) { this.messageHandler.ShowVerboseMessages = true; } else if ("?" == parameter || "help" == parameter) { this.showHelp = true; return; } else { this.unparsedArgs.Add(arg); } } else if (arg.Length > 1 && '@' == arg[0]) { this.ParseCommandLine(CommandLineResponseFile.Parse(arg.Substring(1))); } else { this.unparsedArgs.Add(arg); } } }
/// <summary> /// Parse the commandline arguments. /// </summary> /// <param name="args">Commandline arguments.</param> private void ParseCommandLine(string[] args) { bool usingTransformType = false; for (int i = 0; i < args.Length; ++i) { string arg = args[i]; if (null == arg || 0 == arg.Length) // skip blank arguments { continue; } if ('-' == arg[0] || '/' == arg[0]) { string parameter = arg.Substring(1); if ("a" == parameter) { this.adminImage = true; } else if ("ax" == parameter) { this.exportBasePath = CommandLine.GetDirectory(parameter, this.messageHandler, args, ++i); if (String.IsNullOrEmpty(this.exportBasePath)) { return; } this.adminImage = true; } else if ("ext" == parameter) { if (!CommandLine.IsValidArg(args, ++i)) { this.messageHandler.Display(this, WixErrors.TypeSpecificationForExtensionRequired("-ext")); return; } this.extensionList.Add(args[i]); } else if ("nologo" == parameter) { this.showLogo = false; } else if ("notidy" == parameter) { this.tidy = false; } else if ("o" == parameter || "out" == parameter) { this.outputFile = CommandLine.GetFile(parameter, this.messageHandler, args, ++i); if (String.IsNullOrEmpty(this.outputFile)) { return; } } else if ("p" == parameter) { this.preserveUnchangedRows = true; } else if ("pedantic" == parameter) { this.showPedanticMessages = true; } else if ("swall" == parameter) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("swall", "sw")); this.messageHandler.SuppressAllWarnings = true; } else if (parameter.StartsWith("sw", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { this.messageHandler.SuppressAllWarnings = true; } else { int suppressWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= suppressWarning) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } this.messageHandler.SuppressWarningMessage(suppressWarning); } } catch (FormatException) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } catch (OverflowException) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } } else if ("wxall" == parameter) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("wxall", "wx")); this.messageHandler.WarningAsError = true; } else if (parameter.StartsWith("wx", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { this.messageHandler.WarningAsError = true; } else { int elevateWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= elevateWarning) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } this.messageHandler.ElevateWarningMessage(elevateWarning); } } catch (FormatException) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } catch (OverflowException) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } } else if ("serr" == parameter) { // arguments consistent with msitran.exe if (!CommandLine.IsValidArg(args, ++i)) { this.messageHandler.Display(this, WixErrors.ExpectedArgument(parameter)); return; } if (usingTransformType) { this.messageHandler.Display(this, WixErrors.IllegalValidationArguments()); } else { switch (args[i].ToLower()) { case "a": this.validationFlags |= TransformFlags.ErrorAddExistingRow; break; case "b": this.validationFlags |= TransformFlags.ErrorDeleteMissingRow; break; case "c": this.validationFlags |= TransformFlags.ErrorAddExistingTable; break; case "d": this.validationFlags |= TransformFlags.ErrorDeleteMissingTable; break; case "e": this.validationFlags |= TransformFlags.ErrorUpdateMissingRow; break; case "f": this.validationFlags |= TransformFlags.ErrorChangeCodePage; break; default: this.messageHandler.Display(this, WixErrors.ExpectedArgument(parameter)); break; } } } else if ("t" == parameter) { if (!CommandLine.IsValidArg(args, ++i)) { this.messageHandler.Display(this, WixErrors.ExpectedArgument(parameter)); return; } if (0 != this.validationFlags) { this.messageHandler.Display(this, WixErrors.IllegalValidationArguments()); } else { switch (args[i].ToLower()) { case "language": this.validationFlags = TransformFlags.LanguageTransformDefault; break; case "instance": this.validationFlags = TransformFlags.InstanceTransformDefault; break; case "patch": this.validationFlags = TransformFlags.PatchTransformDefault; break; default: this.messageHandler.Display(this, WixErrors.ExpectedArgument(parameter)); return; } usingTransformType = true; } } else if ("v" == parameter) { this.messageHandler.ShowVerboseMessages = true; } else if ("val" == parameter) { // arguments consistent with msitran.exe if (!CommandLine.IsValidArg(args, ++i)) { this.messageHandler.Display(this, WixErrors.ExpectedArgument(parameter)); return; } if (usingTransformType) { this.messageHandler.Display(this, WixErrors.IllegalValidationArguments()); } else { switch (args[i].ToLower()) { case "g": this.validationFlags |= TransformFlags.ValidateUpgradeCode; break; case "l": this.validationFlags |= TransformFlags.ValidateLanguage; break; case "r": this.validationFlags |= TransformFlags.ValidateProduct; break; case "s": this.validationFlags |= TransformFlags.ValidateMajorVersion; break; case "t": this.validationFlags |= TransformFlags.ValidateMinorVersion; break; case "u": this.validationFlags |= TransformFlags.ValidateUpdateVersion; break; case "v": this.validationFlags |= TransformFlags.ValidateNewLessBaseVersion; break; case "w": this.validationFlags |= TransformFlags.ValidateNewLessEqualBaseVersion; break; case "x": this.validationFlags |= TransformFlags.ValidateNewEqualBaseVersion; break; case "y": this.validationFlags |= TransformFlags.ValidateNewGreaterEqualBaseVersion; break; case "z": this.validationFlags |= TransformFlags.ValidateNewGreaterBaseVersion; break; default: this.messageHandler.Display(this, WixErrors.ExpectedArgument(parameter)); break; } } } else if ("x" == parameter) { this.exportBasePath = CommandLine.GetDirectory(parameter, this.messageHandler, args, ++i); if (String.IsNullOrEmpty(this.exportBasePath)) { return; } } else if ("xi" == parameter) { this.xmlInputs = true; } else if ("xo" == parameter) { this.xmlOutput = true; } else if ("?" == parameter || "help" == parameter) { this.showHelp = true; return; } else { this.invalidArgs.Add(parameter); } } else if ('@' == arg[0]) { this.ParseCommandLine(CommandLineResponseFile.Parse(arg.Substring(1))); } else { string inputFile = CommandLine.VerifyPath(this.messageHandler, arg); if (String.IsNullOrEmpty(inputFile)) { return; } this.inputFiles.Add(inputFile); } } }
/// <summary> /// Parse the commandline arguments. /// </summary> /// <param name="args">Commandline arguments.</param> public string[] Parse(string[] args) { List <string> unprocessed = new List <string>(); for (int i = 0; i < args.Length; ++i) { string arg = args[i]; if (String.IsNullOrEmpty(arg)) // skip blank arguments { continue; } if (1 == arg.Length) // treat '-' and '@' as filenames when by themselves. { unprocessed.Add(arg); } else if ('-' == arg[0] || '/' == arg[0]) { string parameter = arg.Substring(1); if ('d' == parameter[0]) { if (1 >= parameter.Length || '=' == parameter[1]) { Messaging.Instance.OnMessage(WixErrors.InvalidVariableDefinition(arg)); break; } parameter = arg.Substring(2); string[] value = parameter.Split("=".ToCharArray(), 2); if (this.PreprocessorVariables.ContainsKey(value[0])) { Messaging.Instance.OnMessage(WixErrors.DuplicateVariableDefinition(value[0], (1 == value.Length) ? String.Empty : value[1], this.PreprocessorVariables[value[0]])); break; } if (1 == value.Length) { this.PreprocessorVariables.Add(value[0], String.Empty); } else { this.PreprocessorVariables.Add(value[0], value[1]); } } else if ('I' == parameter[0]) { this.IncludeSearchPaths.Add(parameter.Substring(1)); } else if ("ext" == parameter) { if (!CommandLine.IsValidArg(args, ++i)) { Messaging.Instance.OnMessage(WixErrors.TypeSpecificationForExtensionRequired("-ext")); break; } else { this.Extensions.Add(args[i]); } } else if ("nologo" == parameter) { this.ShowLogo = false; } else if ("o" == parameter || "out" == parameter) { string path = CommandLine.GetFileOrDirectory(parameter, args, ++i); if (!String.IsNullOrEmpty(path)) { if (path.EndsWith("\\", StringComparison.Ordinal) || path.EndsWith("/", StringComparison.Ordinal)) { this.OutputFolder = path; } else { this.OutputFile = path; } } else { break; } } else if ("pedantic" == parameter) { this.ShowPedanticMessages = true; } else if ("arch" == parameter) { if (!CommandLine.IsValidArg(args, ++i)) { Messaging.Instance.OnMessage(WixErrors.InvalidPlatformParameter(parameter, String.Empty)); break; } if (String.Equals(args[i], "intel", StringComparison.OrdinalIgnoreCase) || String.Equals(args[i], "x86", StringComparison.OrdinalIgnoreCase)) { this.Platform = Platform.X86; } else if (String.Equals(args[i], "x64", StringComparison.OrdinalIgnoreCase)) { this.Platform = Platform.X64; } else if (String.Equals(args[i], "intel64", StringComparison.OrdinalIgnoreCase) || String.Equals(args[i], "ia64", StringComparison.OrdinalIgnoreCase)) { this.Platform = Platform.IA64; } else if (String.Equals(args[i], "arm", StringComparison.OrdinalIgnoreCase)) { this.Platform = Platform.ARM; } else { Messaging.Instance.OnMessage(WixErrors.InvalidPlatformParameter(parameter, args[i])); } } else if ('p' == parameter[0]) { string file = parameter.Substring(1); this.PreprocessFile = String.IsNullOrEmpty(file) ? "con:" : file; } else if (parameter.StartsWith("sw", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { Messaging.Instance.SuppressAllWarnings = true; } else { int suppressWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= suppressWarning) { Messaging.Instance.OnMessage(WixErrors.IllegalSuppressWarningId(paramArg)); } Messaging.Instance.SuppressWarningMessage(suppressWarning); } } catch (FormatException) { Messaging.Instance.OnMessage(WixErrors.IllegalSuppressWarningId(paramArg)); } catch (OverflowException) { Messaging.Instance.OnMessage(WixErrors.IllegalSuppressWarningId(paramArg)); } } else if (parameter.StartsWith("wx", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { Messaging.Instance.WarningsAsError = true; } else { int elevateWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= elevateWarning) { Messaging.Instance.OnMessage(WixErrors.IllegalWarningIdAsError(paramArg)); } Messaging.Instance.ElevateWarningMessage(elevateWarning); } } catch (FormatException) { Messaging.Instance.OnMessage(WixErrors.IllegalWarningIdAsError(paramArg)); } catch (OverflowException) { Messaging.Instance.OnMessage(WixErrors.IllegalWarningIdAsError(paramArg)); } } else if ("v" == parameter) { Messaging.Instance.ShowVerboseMessages = true; } else if ("?" == parameter || "help" == parameter) { this.ShowHelp = true; break; } else { unprocessed.Add(arg); } } else if ('@' == arg[0]) { string[] parsedArgs = CommandLineResponseFile.Parse(arg.Substring(1)); string[] unparsedArgs = this.Parse(parsedArgs); unprocessed.AddRange(unparsedArgs); } else { unprocessed.Add(arg); } } return(unprocessed.ToArray()); }