context: //
  // NAntContrib
  // Copyright (C) 2001-2003 Gerry Shaw
  //
  //
  // This library is free software; you can redistribute it and/or
  // modify it under the terms of the GNU Lesser General Public
  // License as published by the Free Software Foundation; either
  // version 2.1 of the License, or (at your option) any later version.
  //
  // This library is distributed in the hope that it will be useful,
  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  // Lesser General Public License for more details.
  //
  // You should have received a copy of the GNU Lesser General Public
  // License along with this library; if not, write to the Free Software
  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  //
  // Ian MacLean (ian@maclean.ms)
  
  using System;
  using System.Collections.Specialized;
  using System.Globalization;
  using System.IO;
  
  using NAnt.Core;
  using NAnt.Core.Types;
  using NAnt.Core.Tasks;
  using NAnt.Core.Attributes;
  
  namespace NAnt.Contrib.Tasks {
      /// <summary>
      /// Registers an assembly for use from COM clients.
      /// </summary>
      /// <remarks>
      ///   <para>
      ///   Refer to the <see href="ms-help://MS.VSCC/MS.MSDNVS/cptools/html/cpgrfassemblyregistrationtoolregasmexe.htm">Regasm</see> 
      ///   documentation for more information on the regasm tool.
      ///   </para>
      /// </remarks>
      /// <example>
      ///   <para>
      ///   Register a single assembly.
      ///   </para>
      ///   <code>
      ///     <![CDATA[
      /// <regasm assembly="myAssembly.dll" />
      ///     ]]>
      ///   </code>
      /// </example>
      /// <example>
      ///   <para>
      ///   Register an assembly while exporting a typelibrary.
      ///   </para>
      ///   <code>
      ///     <![CDATA[
      /// <regasm assembly="myAssembly.dll" typelib="myAssembly.tlb" />
      ///     ]]>
      ///   </code>
      /// </example>
      /// <example>
      ///   <para>
      ///   Register a set of assemblies at once.
      ///   </para>
      ///   <code>
      ///     <![CDATA[
      /// <regasm unregister="false" codebase="true">
      ///     <fileset>
      ///         <include name="**/*.dll" />
        ///       <exclude name="notanassembly.dll" />
      ///     </fileset>
      /// </regasm>
      ///     ]]>
      ///   </code>
      /// </example>
      [TaskName("regasm")]
      [ProgramLocation(LocationType.FrameworkDir)]
      public class RegasmTask : ExternalProgramBase {
          #region Private Instance Fields
  
          private FileInfo _assemblyFile;
          private FileInfo _regfile;
          private FileInfo _typelib;
          private bool _codebase;
          private bool _exporttypelib;
          private bool _unregister;
          private bool _registered;
          private FileSet _fileset = new FileSet();
  
          #endregion Private Instance Fields
  
          #region Public Instance Properties
  
         /// <summary>
         /// The name of the file to register. This is provided as an alternate 
         /// to using the task's fileset.
         /// </summary>
          [TaskAttribute("assembly")]
          public FileInfo AssemblyFile {
              get { return _assemblyFile; }
              set { _assemblyFile = value; }
          }
  
          /// <summary>
          /// Registry file to export to instead of entering the types directly 
          /// into the registry. If a fileset is used then the entries are all 
          /// collated into this file.
          /// </summary>
          [TaskAttribute("regfile")]
          public FileInfo RegistryFile {
              get { return _regfile; }
              set { _regfile = value; }
          }
  
          /// <summary>
          /// Set the code base registry setting.
          /// </summary>
          [TaskAttribute("codebase")]
          [BooleanValidator()]
          public bool CodeBase {
              get { return _codebase; }
              set { _codebase = value; }
          }
  
          /// <summary>
          /// Export a typelib and register it. The typelib will have the same 
          /// name as the source assembly unless the <see cref="TypeLib" /> 
          /// attribute is used.
          /// </summary>
          [TaskAttribute("exporttypelib")]
          [BooleanValidator()]
          public bool ExportTypelib {
              get { return _exporttypelib; }
              set { _exporttypelib = value; }
          }
  
          /// <summary>
          /// Only refer to already registered type libraries.
          /// </summary>
          [TaskAttribute("registered")]
          [BooleanValidator()]
          public bool Registered {
              get { return _registered; }
              set { _registered = value; }
          }
          
          /// <summary>
          /// Export the assembly to the specified type library and register it.
          /// This attribute is ignored when a fileset is specified.
          /// </summary>
          [TaskAttribute("typelib")]
          public FileInfo TypeLib {
              get { return _typelib; }
              set { _typelib = value; }
          }
          
          /// <summary>
          /// Unregister the assembly. The default is <see langword="false" />.
          /// </summary>
          [TaskAttribute("unregister")]
          [BooleanValidator()]
          public bool Unregister {
              get { return _unregister; }
              set { _unregister = value; }
          }
                 
          /// <summary>
          /// The set of files to register.
          /// </summary>
          [BuildElement("fileset")]
          public FileSet RegasmFileSet {
              get { return _fileset; }
              set { _fileset = value; }
          }
  
          #endregion Public Instance Properties
  
          public override string ProgramArguments {
              get {
                  string args = "";
  
                  if (Unregister) {
                      args += " /unregister ";
                  }
                  if (ExportTypelib && TypeLib != null) {
                      args += string.Format(CultureInfo.InvariantCulture,
                          " /tlb:\"{0}\"", TypeLib.FullName);
                  }
                  if (CodeBase) {
                      args += " /codebase";
                  }
                  if (RegistryFile != null) {
                      args += string.Format(CultureInfo.InvariantCulture,
                          " /regfile:\"{0}\"", RegistryFile.FullName);
                  }
                  if (Registered) {
                       args += " /registered";
                  }
                  if (Verbose) {
                       args += " /verbose";
                  } else {
                       args += " /silent";
                  }
                  args += " /nologo";
  
                  args += " \"" + AssemblyFile.FullName + "\"";
                  return args;
              }
          }
  
          protected override void ExecuteTask() {
              if (AssemblyFile != null) {
                  Log(Level.Info, "{0} '{1}' for COM Interop", 
                      Unregister ? "UnRegistering" : "Registering", 
                      AssemblyFile.FullName);
  
  
gt:                 if (ExportTypelib && TypeLib == null) {