/// <summary> /// Creates the library. /// </summary> protected override void ExecuteTask() { // ensure base directory is set, even if fileset was not initialized // from XML if (Sources.BaseDirectory == null) { Sources.BaseDirectory = new DirectoryInfo(Project.BaseDirectory); } if (LibDirs.BaseDirectory == null) { LibDirs.BaseDirectory = new DirectoryInfo(Project.BaseDirectory); } if (!NeedsCompiling()) { return; } Log(Level.Info, "Combining {0} files to '{1}'.", Sources.FileNames.Count, OutputFile.FullName); // Create temp response file to hold compiler options _responseFileName = Path.GetTempFileName(); StreamWriter writer = new StreamWriter(_responseFileName); try { // specify the output file writer.WriteLine("/OUT:\"{0}\"", OutputFile.FullName); // write user provided options if (Options != null) { writer.WriteLine(Options); } // write each of the filenames foreach (string filename in Sources.FileNames) { writer.WriteLine(ArgumentUtils.QuoteArgumentValue(filename, BackslashProcessingMethod.None)); } // write symbols foreach (Symbol symbol in Symbols) { if (symbol.IfDefined && !symbol.UnlessDefined) { writer.WriteLine("/INCLUDE:{0}", ArgumentUtils.QuoteArgumentValue( symbol.SymbolName, BackslashProcessingMethod.Duplicate)); } } // names of default libraries to ignore foreach (Library ignoreLibrary in IgnoreLibraries) { if (ignoreLibrary.IfDefined && !ignoreLibrary.UnlessDefined) { writer.WriteLine("/NODEFAULTLIB:{0}", ArgumentUtils.QuoteArgumentValue( ignoreLibrary.LibraryName, BackslashProcessingMethod.Duplicate)); } } // write each of the libdirs foreach (string libdir in LibDirs.DirectoryNames) { writer.WriteLine("/LIBPATH:{0}", ArgumentUtils.QuoteArgumentValue( libdir, BackslashProcessingMethod.None)); } if (ModuleDefinitionFile != null) { writer.WriteLine("/DEF:\"{0}\"", ModuleDefinitionFile.FullName); } // suppresses display of the sign-on banner writer.WriteLine("/nologo"); writer.Close(); if (Verbose) { // display response file contents Log(Level.Info, "Contents of {0}.", _responseFileName); StreamReader reader = File.OpenText(_responseFileName); Log(Level.Info, reader.ReadToEnd()); reader.Close(); } // call base class to do the actual work base.ExecuteTask(); } finally { // make sure we delete response file even if an exception is thrown writer.Close(); // make sure stream is closed or file cannot be deleted File.Delete(_responseFileName); _responseFileName = null; } }
/// <summary> /// Quotes an argument value and duplicates trailing backslahes. /// </summary> /// <param name="value">The argument value to quote.</param> /// <returns> /// The quotes argument value. /// </returns> public static string QuoteArgumentValue(string value) { return ArgumentUtils.QuoteArgumentValue(value, BackslashProcessingMethod.Duplicate); }
/// <summary> /// Writes the response file for <c>midl.exe</c>. /// </summary> private void WriteResponseFile(TextWriter writer) { // suppresses display of the sign-on banner writer.WriteLine("/nologo"); writer.WriteLine("/env " + _env); if (_acf != null) { writer.WriteLine("/acf {0}", _acf); } if (_align != null) { writer.WriteLine("/align {0}", _align); } if (_appConfig) { writer.WriteLine("/app_config"); } if (_char != null) { writer.WriteLine("/char {0}", _char); } if (_client != null) { writer.WriteLine("/client {0}", _client); } if (_cstub != null) { writer.WriteLine("/cstub {0}", _cstub); } if (_dlldata != null) { writer.WriteLine("/dlldata \"{0}\"", DllData.FullName); } if (_Oi != null) { writer.WriteLine("/Oi" + _Oi); } if (Tlb != null) { writer.WriteLine("/tlb \"{0}\"", Tlb.FullName); } if (_header != null) { writer.WriteLine("/header \"{0}\"", Header.FullName); } if (Iid != null) { writer.WriteLine("/iid \"{0}\"", Iid.FullName); } if (Proxy != null) { writer.WriteLine("/proxy \"{0}\"", Proxy.FullName); } foreach (Option define in Defines) { if (!define.IfDefined || define.UnlessDefined) { continue; } if (define.Value == null) { writer.WriteLine("/D " + ArgumentUtils.FixTrailingBackslash(define.OptionName)); } else { writer.WriteLine("/D " + define.OptionName + "=" + ArgumentUtils.FixTrailingBackslash(define.Value)); } } foreach (Option undefine in Undefines) { if (!undefine.IfDefined || undefine.UnlessDefined) { continue; } writer.WriteLine("/U " + ArgumentUtils.QuoteArgumentValue( undefine.OptionName, BackslashProcessingMethod.Fix)); } foreach (Option option in _options) { if (IfDefined && !UnlessDefined) { if (option.Value == null) { writer.WriteLine(option.OptionName); } else { writer.WriteLine(option.OptionName + " " + option.Value); } } } // append user provided include directories foreach (string include in IncludeDirs.DirectoryNames) { writer.WriteLine("/I {0}", ArgumentUtils.QuoteArgumentValue( include, BackslashProcessingMethod.Clean)); } writer.WriteLine("\"{0}\"", Filename.FullName); }