/// <summary> /// Fills the provided CommandLineBuilderExtension with all the command line options used when /// executing this tool that can go into a response file. /// </summary> /// <comments> /// ResGen 3.5 and earlier doesn't support response files, but ResGen 4.0 and later does. /// </comments> /// <param name="commandLine">Gets filled with command line options</param> protected internal override void AddResponseFileCommands(CommandLineBuilderExtension commandLine) { string pathToResGen = GenerateResGenFullPath(); // Only do anything if we can actually use response files if (pathToResGen != null && NativeMethodsShared.IsWindows && !pathToResGen.Equals( ToolLocationHelper.GetPathToDotNetFrameworkSdkFile( "resgen.exe", TargetDotNetFrameworkVersion.Version35), StringComparison.OrdinalIgnoreCase) && String.IsNullOrEmpty(StronglyTypedLanguage)) { // 4.0 resgen.exe does support response files, so we can return the resgen arguments here! CommandLineBuilderExtension resGenArguments = new CommandLineBuilderExtension(); GenerateResGenCommands(resGenArguments, true /* arguments must be line-delimited */); commandLine.AppendTextUnquoted(resGenArguments.ToString()); } else { // return nothing -- if it's not 4.0, or if we're building strongly typed resources, we assume that, // as far as ToolTask is concerned at least, response files are not supported. } }
/// <summary> /// Fills the provided CommandLineBuilderExtension with all the command line options used when /// executing this tool that must go on the command line /// </summary> /// <comments> /// Has to be command line commands because ResGen 3.5 and earlier don't know about /// response files. /// </comments> /// <param name="commandLine">Gets filled with command line options</param> protected internal override void AddCommandLineCommands(CommandLineBuilderExtension commandLine) { ErrorUtilities.VerifyThrow(!ResGen.IsNullOrEmpty(InputFiles), "If InputFiles is empty, the task should have returned before reaching this point"); CommandLineBuilderExtension resGenArguments = new CommandLineBuilderExtension(); GenerateResGenCommands(resGenArguments, false /* don't line-delimit arguments; spaces are just fine */); string pathToResGen = GenerateResGenFullPath(); if ( pathToResGen != null && !pathToResGen.Equals(NativeMethodsShared.GetLongFilePath(ToolLocationHelper.GetPathToDotNetFrameworkSdkFile("resgen.exe", TargetDotNetFrameworkVersion.Version35)), StringComparison.OrdinalIgnoreCase) && String.IsNullOrEmpty(StronglyTypedLanguage) ) { // 4.0 resgen.exe does support response files (at least as long as you're not building an STR), so we can // make use of them here by returning nothing! } else { // otherwise, the toolname is ResGen.exe and we just need the resgen arguments in CommandLineCommands. commandLine.AppendTextUnquoted(resGenArguments.ToString()); } }
/// <summary> /// Adds the arguments for cmd.exe /// </summary> /// <param name="commandLine">command line builder class to add arguments to</param> protected internal override void AddCommandLineCommands(CommandLineBuilderExtension commandLine) { // Create the batch file now, // so we have the file name for the cmd.exe command line CreateTemporaryBatchFile(); string batchFileForCommandLine = _batchFile; // Unix consoles cannot have their encodings changed in place (like chcp on windows). // Instead, unix scripts receive encoding information via environment variables before invocation. // In consequence, encoding setup has to be performed outside the script, not inside it. if (NativeMethodsShared.IsUnixLike) { commandLine.AppendSwitch("-c"); commandLine.AppendTextUnquoted(" \""); commandLine.AppendTextUnquoted("export LANG=en_US.UTF-8; export LC_ALL=en_US.UTF-8; . "); commandLine.AppendFileNameIfNotNull(batchFileForCommandLine); commandLine.AppendTextUnquoted("\""); } else { if (NativeMethodsShared.IsWindows) { commandLine.AppendSwitch("/Q"); // echo off if (!Traits.Instance.EscapeHatches.UseAutoRunWhenLaunchingProcessUnderCmd) { commandLine.AppendSwitch("/D"); // do not load AutoRun configuration from the registry (perf) } commandLine.AppendSwitch("/C"); // run then terminate // If for some crazy reason the path has a & character and a space in it // then get the short path of the temp path, which should not have spaces in it // and then escape the & if (batchFileForCommandLine.Contains("&") && !batchFileForCommandLine.Contains("^&")) { batchFileForCommandLine = NativeMethodsShared.GetShortFilePath(batchFileForCommandLine); batchFileForCommandLine = batchFileForCommandLine.Replace("&", "^&"); } } commandLine.AppendFileNameIfNotNull(batchFileForCommandLine); } }
protected internal override void AddCommandLineCommands(CommandLineBuilderExtension commandLine) { #if RUNTIME_TYPE_NETCORE commandLine.AppendFileNameIfNotNull(_executablePath.Value); commandLine.AppendTextUnquoted(" "); #endif commandLine.AppendSwitchIfTrue("/noconfig", NoConfig); if (References != null) { foreach (ITaskItem reference in References) { commandLine.AppendSwitchIfNotNull(ReferenceSwitch, reference.ItemSpec); } } commandLine.AppendPlusOrMinusSwitch("/deterministic", Deterministic); commandLine.AppendSwitchIfTrue("/nologo", NoLogo); commandLine.AppendPlusOrMinusSwitch("/optimize", Optimize); commandLine.AppendSwitchIfNotNull("/target:", TargetType); commandLine.AppendSwitchIfNotNull("/out:", OutputAssembly); commandLine.AppendFileNamesIfNotNull(Sources, " "); }
/// <summary> /// Generate the command line to be passed to resgen.exe, sans the path to the tool. /// </summary> private void GenerateResGenCommands(CommandLineBuilderExtension resGenArguments, bool useForResponseFile) { resGenArguments = resGenArguments ?? new CommandLineBuilderExtension(); if (ResGen.IsNullOrEmpty(OutputFiles)) { GenerateOutputFileNames(); } // Append boolean flags if requested string useSourcePathSwitch = "/useSourcePath" + (useForResponseFile ? "\n" : String.Empty); string publicClassSwitch = "/publicClass" + (useForResponseFile ? "\n" : String.Empty); resGenArguments.AppendWhenTrue(useSourcePathSwitch, Bag, "UseSourcePath"); resGenArguments.AppendWhenTrue(publicClassSwitch, Bag, "PublicClass"); // append the references, if any if (References != null) { foreach (ITaskItem reference in References) { // ResGen.exe response files frown on quotes in filenames, even if there are // spaces in the names of the files. if (useForResponseFile && reference != null) { resGenArguments.AppendTextUnquoted("/r:"); resGenArguments.AppendTextUnquoted(reference.ItemSpec); resGenArguments.AppendTextUnquoted("\n"); } else { resGenArguments.AppendSwitchIfNotNull("/r:", reference); } } } if (String.IsNullOrEmpty(StronglyTypedLanguage)) { // append the compile switch resGenArguments.AppendSwitch("/compile" + (useForResponseFile ? "\n" : String.Empty)); // append the resources to compile if (InputFiles != null && InputFiles.Length > 0) { ITaskItem[] inputFiles = InputFiles; ITaskItem[] outputFiles = OutputFiles; for (int i = 0; i < inputFiles.Length; ++i) { if (useForResponseFile) { // ResGen.exe response files frown on quotes in filenames, even if there are // spaces in the names of the files. if (inputFiles[i] != null && outputFiles[i] != null) { resGenArguments.AppendTextUnquoted(inputFiles[i].ItemSpec); resGenArguments.AppendTextUnquoted(","); resGenArguments.AppendTextUnquoted(outputFiles[i].ItemSpec); resGenArguments.AppendTextUnquoted("\n"); } } else { resGenArguments.AppendFileNamesIfNotNull ( new ITaskItem[] { inputFiles[i], outputFiles[i] }, "," ); } } } } else { // append the resource to compile resGenArguments.AppendFileNamesIfNotNull(InputFiles, " "); resGenArguments.AppendFileNamesIfNotNull(OutputFiles, " "); // append the strongly-typed resource details resGenArguments.AppendSwitchIfNotNull ( "/str:", new string[] { StronglyTypedLanguage, StronglyTypedNamespace, StronglyTypedClassName, StronglyTypedFileName }, "," ); } }
/// <summary> /// Given the list of inputs and outputs, returns the number of resources (starting at the provided initial index) /// that can fit onto the commandline without exceeding MaximumCommandLength. /// </summary> private int CalculateResourceBatchSize(List<ITaskItem> inputsToProcess, List<ITaskItem> outputsToProcess, string resourcelessCommand, int initialResourceIndex) { CommandLineBuilderExtension currentCommand = new CommandLineBuilderExtension(); if (!String.IsNullOrEmpty(resourcelessCommand)) { currentCommand.AppendTextUnquoted(resourcelessCommand); } int i = initialResourceIndex; while (currentCommand.Length < s_maximumCommandLength && i < inputsToProcess.Count) { currentCommand.AppendFileNamesIfNotNull ( new ITaskItem[] { inputsToProcess[i], outputsToProcess[i] }, "," ); i++; } int numberOfResourcesToAdd = 0; if (currentCommand.Length <= s_maximumCommandLength) { // We've successfully added all the rest. numberOfResourcesToAdd = i - initialResourceIndex; } else { // The last one added tossed us over the edge. numberOfResourcesToAdd = i - initialResourceIndex - 1; } return numberOfResourcesToAdd; }
protected void AddResponseFileCommandsImpl(CommandLineBuilderExtension cmdline) { XSharpCommandLineBuilder commandLine = (XSharpCommandLineBuilder)cmdline; // The managed compiler command line options are called from the cscCompiler options if (this.Dialect?.Length > 0) { cmdline.AppendTextUnquoted(" /dialect:" + this.Dialect); } AddCscCompilerCommands(commandLine); AddVOCompatibilityCommands(commandLine); }
/// <summary> /// Generate the command line to be passed to resgen.exe, sans the path to the tool. /// </summary> private void GenerateResGenCommands(CommandLineBuilderExtension resGenArguments, bool useForResponseFile) { resGenArguments = resGenArguments ?? new CommandLineBuilderExtension(); if (ResGen.IsNullOrEmpty(OutputFiles)) { GenerateOutputFileNames(); } // Append boolean flags if requested string useSourcePathSwitch = "/useSourcePath" + (useForResponseFile ? "\n" : String.Empty); string publicClassSwitch = "/publicClass" + (useForResponseFile ? "\n" : String.Empty); resGenArguments.AppendWhenTrue(useSourcePathSwitch, Bag, "UseSourcePath"); resGenArguments.AppendWhenTrue(publicClassSwitch, Bag, "PublicClass"); // append the references, if any if (References != null) { foreach (ITaskItem reference in References) { // ResGen.exe response files frown on quotes in filenames, even if there are // spaces in the names of the files. if (useForResponseFile && reference != null) { resGenArguments.AppendTextUnquoted("/r:"); resGenArguments.AppendTextUnquoted(reference.ItemSpec); resGenArguments.AppendTextUnquoted("\n"); } else { resGenArguments.AppendSwitchIfNotNull("/r:", reference); } } } if (String.IsNullOrEmpty(StronglyTypedLanguage)) { // append the compile switch resGenArguments.AppendSwitch("/compile" + (useForResponseFile ? "\n" : String.Empty)); // append the resources to compile if (InputFiles != null && InputFiles.Length > 0) { ITaskItem[] inputFiles = InputFiles; ITaskItem[] outputFiles = OutputFiles; for (int i = 0; i < inputFiles.Length; ++i) { if (useForResponseFile) { // ResGen.exe response files frown on quotes in filenames, even if there are // spaces in the names of the files. if (inputFiles[i] != null && outputFiles[i] != null) { resGenArguments.AppendTextUnquoted(inputFiles[i].ItemSpec); resGenArguments.AppendTextUnquoted(","); resGenArguments.AppendTextUnquoted(outputFiles[i].ItemSpec); resGenArguments.AppendTextUnquoted("\n"); } } else { resGenArguments.AppendFileNamesIfNotNull ( new ITaskItem[] { inputFiles[i], outputFiles[i] }, "," ); } } } } else { // append the resource to compile resGenArguments.AppendFileNamesIfNotNull(InputFiles, " "); resGenArguments.AppendFileNamesIfNotNull(OutputFiles, " "); // append the strongly-typed resource details resGenArguments.AppendSwitchIfNotNull ( "/str:", new string[] { StronglyTypedLanguage, StronglyTypedNamespace, StronglyTypedClassName, StronglyTypedFileName }, "," ); } }
/// <summary> /// Fills the provided CommandLineBuilderExtension with all the command line options used when /// executing this tool that must go on the command line /// </summary> /// <comments> /// Has to be command line commands because ResGen 3.5 and earlier don't know about /// response files. /// </comments> /// <param name="commandLine">Gets filled with command line options</param> protected internal override void AddCommandLineCommands(CommandLineBuilderExtension commandLine) { ErrorUtilities.VerifyThrow(!ResGen.IsNullOrEmpty(InputFiles), "If InputFiles is empty, the task should have returned before reaching this point"); CommandLineBuilderExtension resGenArguments = new CommandLineBuilderExtension(); GenerateResGenCommands(resGenArguments, false /* don't line-delimit arguments; spaces are just fine */); string pathToResGen = GenerateResGenFullPath(); if ( pathToResGen != null && !pathToResGen.Equals(NativeMethodsShared.GetLongFilePath(ToolLocationHelper.GetPathToDotNetFrameworkSdkFile("resgen.exe", TargetDotNetFrameworkVersion.Version35)), StringComparison.OrdinalIgnoreCase) && String.IsNullOrEmpty(StronglyTypedLanguage) ) { // 4.0 resgen.exe does support response files (at least as long as you're not building an STR), so we can // make use of them here by returning nothing! } else { // otherwise, the toolname is ResGen.exe and we just need the resgen arguments in CommandLineCommands. commandLine.AppendTextUnquoted(resGenArguments.ToString()); } }
/// <summary> /// Fills the provided CommandLineBuilderExtension with all the command line options used when /// executing this tool that can go into a response file. /// </summary> /// <comments> /// ResGen 3.5 and earlier doesn't support response files, but ResGen 4.0 and later does. /// </comments> /// <param name="commandLine">Gets filled with command line options</param> protected internal override void AddResponseFileCommands(CommandLineBuilderExtension commandLine) { string pathToResGen = GenerateResGenFullPath(); // Only do anything if we can actually use response files if ( pathToResGen != null && !pathToResGen.Equals(ToolLocationHelper.GetPathToDotNetFrameworkSdkFile("resgen.exe", TargetDotNetFrameworkVersion.Version35), StringComparison.OrdinalIgnoreCase) && String.IsNullOrEmpty(StronglyTypedLanguage) ) { // 4.0 resgen.exe does support response files, so we can return the resgen arguments here! CommandLineBuilderExtension resGenArguments = new CommandLineBuilderExtension(); GenerateResGenCommands(resGenArguments, true /* arguments must be line-delimited */); commandLine.AppendTextUnquoted(resGenArguments.ToString()); } else { // return nothing -- if it's not 4.0, or if we're building strongly typed resources, we assume that, // as far as ToolTask is concerned at least, response files are not supported. } }
protected override void AddCommandLineCommands(CommandLineBuilderExtension commandLine) { if (!string.IsNullOrEmpty(JvmOptions)) commandLine.AppendTextUnquoted(" " + JvmOptions.Trim()); }
protected override void AddResponseFileCommands(CommandLineBuilderExtension commandLine) { // the -verbose flag must be included or there's no way to figure out what the output files are commandLine.AppendSwitch("-verbose"); if (!string.IsNullOrEmpty(Encoding)) commandLine.AppendSwitchIfNotNull("-encoding ", Encoding); switch (DebugSymbols) { case "All": commandLine.AppendSwitch("-g");break; case "None": commandLine.AppendSwitch("-g:none");break; case "Specific": if (!string.IsNullOrEmpty(SpecificDebugSymbols)) commandLine.AppendSwitchIfNotNull("-g:", SpecificDebugSymbols); else commandLine.AppendSwitch("-g:none"); break; case "Default": default: break; } if (!string.IsNullOrEmpty(SourceRelease) && !string.Equals(SourceRelease, "Default", StringComparison.OrdinalIgnoreCase)) commandLine.AppendSwitchIfNotNull("-source ", SourceRelease); if (!string.IsNullOrEmpty(TargetRelease) && !string.Equals(TargetRelease, "Default", StringComparison.OrdinalIgnoreCase)) commandLine.AppendSwitchIfNotNull("-target ", TargetRelease); if (!string.IsNullOrEmpty(OutputPath)) commandLine.AppendSwitchIfNotNull("-d ", OutputPath); if (!ShowWarnings) { commandLine.AppendSwitch("-nowarn"); } else if (ShowAllWarnings) { commandLine.AppendSwitch("-Xlint"); commandLine.AppendSwitch("-deprecation"); } if (!string.IsNullOrEmpty(BuildArgs)) commandLine.AppendTextUnquoted(" " + BuildArgs); // reference paths List<string> referencePaths = new List<string>(); foreach (var reference in (References ?? Enumerable.Empty<ITaskItem>())) { string path = GetReferencePath(reference); if (!string.IsNullOrEmpty(path)) referencePaths.Add(path); } if (referencePaths.Count > 0) { commandLine.AppendSwitchIfNotNull("-cp ", referencePaths.ToArray(), ";"); } commandLine.AppendSwitchIfNotNull("-classpath ", ClassPath, ";"); commandLine.AppendFileNamesIfNotNull(Sources, " "); }
private void GenerateResGenCommands(CommandLineBuilderExtension resGenArguments, bool useForResponseFile) { resGenArguments = resGenArguments ?? new CommandLineBuilderExtension(); if (IsNullOrEmpty(this.OutputFiles)) { this.GenerateOutputFileNames(); } string switchName = "/useSourcePath" + (useForResponseFile ? "\n" : string.Empty); string str2 = "/publicClass" + (useForResponseFile ? "\n" : string.Empty); resGenArguments.AppendWhenTrue(switchName, base.Bag, "UseSourcePath"); resGenArguments.AppendWhenTrue(str2, base.Bag, "PublicClass"); if (this.References != null) { foreach (ITaskItem item in this.References) { if (useForResponseFile && (item != null)) { resGenArguments.AppendTextUnquoted("/r:"); resGenArguments.AppendTextUnquoted(item.ItemSpec); resGenArguments.AppendTextUnquoted("\n"); } else { resGenArguments.AppendSwitchIfNotNull("/r:", item); } } } if (string.IsNullOrEmpty(this.StronglyTypedLanguage)) { resGenArguments.AppendSwitch("/compile" + (useForResponseFile ? "\n" : string.Empty)); if ((this.InputFiles != null) && (this.InputFiles.Length > 0)) { ITaskItem[] inputFiles = this.InputFiles; ITaskItem[] outputFiles = this.OutputFiles; for (int i = 0; i < inputFiles.Length; i++) { if (useForResponseFile) { if ((inputFiles[i] != null) && (outputFiles[i] != null)) { resGenArguments.AppendTextUnquoted(inputFiles[i].ItemSpec); resGenArguments.AppendTextUnquoted(","); resGenArguments.AppendTextUnquoted(outputFiles[i].ItemSpec); resGenArguments.AppendTextUnquoted("\n"); } } else { resGenArguments.AppendFileNamesIfNotNull(new ITaskItem[] { inputFiles[i], outputFiles[i] }, ","); } } } } else { resGenArguments.AppendFileNamesIfNotNull(this.InputFiles, " "); resGenArguments.AppendFileNamesIfNotNull(this.OutputFiles, " "); resGenArguments.AppendSwitchIfNotNull("/str:", new string[] { this.StronglyTypedLanguage, this.StronglyTypedNamespace, this.StronglyTypedClassName, this.StronglyTypedFileName }, ","); } }
protected internal override void AddResponseFileCommands(CommandLineBuilderExtension commandLine) { string str = this.GenerateResGenFullPath(); if ((!this.TrackFileAccess && (str != null)) && (str.Equals(ToolLocationHelper.GetPathToDotNetFrameworkSdkFile("resgen.exe", TargetDotNetFrameworkVersion.Version40), StringComparison.OrdinalIgnoreCase) && string.IsNullOrEmpty(this.StronglyTypedLanguage))) { CommandLineBuilderExtension resGenArguments = new CommandLineBuilderExtension(); this.GenerateResGenCommands(resGenArguments, true); commandLine.AppendTextUnquoted(resGenArguments.ToString()); } }
protected internal override void AddCommandLineCommands(CommandLineBuilderExtension commandLine) { Microsoft.Build.Shared.ErrorUtilities.VerifyThrow(!IsNullOrEmpty(this.InputFiles), "If InputFiles is empty, the task should have returned before reaching this point"); CommandLineBuilderExtension resGenArguments = new CommandLineBuilderExtension(); this.GenerateResGenCommands(resGenArguments, false); string str = this.GenerateResGenFullPath(); if (this.TrackFileAccess) { string rootFiles = FileTracker.FormatRootingMarker(this.InputFiles); string temporaryFile = Microsoft.Build.Shared.FileUtilities.GetTemporaryFile(); string fileTrackerPath = FileTracker.GetFileTrackerPath(this.ToolType, this.TrackerFrameworkPath); using (StreamWriter writer = new StreamWriter(temporaryFile, false, this.ResponseFileEncoding)) { writer.Write(FileTracker.TrackerResponseFileArguments(fileTrackerPath, this.TrackerLogDirectory, rootFiles)); } commandLine.AppendTextUnquoted(this.GetResponseFileSwitch(temporaryFile)); commandLine.AppendSwitch(FileTracker.TrackerCommandArguments(str ?? string.Empty, resGenArguments.ToString())); } else if (((str == null) || !str.Equals(Microsoft.Build.Shared.NativeMethodsShared.GetLongFilePath(ToolLocationHelper.GetPathToDotNetFrameworkSdkFile("resgen.exe", TargetDotNetFrameworkVersion.Version40)), StringComparison.OrdinalIgnoreCase)) || !string.IsNullOrEmpty(this.StronglyTypedLanguage)) { commandLine.AppendTextUnquoted(resGenArguments.ToString()); } }
private int CalculateResourceBatchSize(List<ITaskItem> inputsToProcess, List<ITaskItem> outputsToProcess, string resourcelessCommand, int initialResourceIndex) { CommandLineBuilderExtension extension = new CommandLineBuilderExtension(); if (!string.IsNullOrEmpty(resourcelessCommand)) { extension.AppendTextUnquoted(resourcelessCommand); } int num = initialResourceIndex; while ((extension.Length < MaximumCommandLength) && (num < inputsToProcess.Count)) { extension.AppendFileNamesIfNotNull(new ITaskItem[] { inputsToProcess[num], outputsToProcess[num] }, ","); num++; } if (num == inputsToProcess.Count) { return (num - initialResourceIndex); } return ((num - initialResourceIndex) - 1); }