// // NAntContrib // Copyright (C) 2001-2002 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 // // Arjen Poutsma (poutsma@yahoo.com) using System; using System.Text; using NAnt.Core; using NAnt.Core.Attributes; using NAnt.Core.Tasks; namespace NAnt.Contrib.Tasks { /// Installs or removes .NET Services. /// /// This tasks provides the same functionality as the regsvcs tool provided in the .NET SDK. /// It performs the following actions: /// /// /// Loads and registers an assembly. /// /// /// Generates, registers, and installs a type library into a specified COM+ application. /// /// /// Configures services that are added programmatically to your class. /// /// /// Refer to the .NET Services Installation Tool (Regsvcs.exe) for more information. /// /// /// Adds all public classes contained in myTest.dll to a COM+ 1.0 application and produces the myTest.tlb type library. If the application already exists, it is overwritten. /// <regsvcs assembly="myTest.dll" > /// Adds all public classes contained in myTest.dll to myTargetApp and produces the myTest.tlb type library. If the application already exists, it is overwritten. /// <regsvcs assembly="myTest.dll" appname="myTargetApp" > /// Adds all public classes contained in myTest.dll to a COM+ 1.0 application and produces the myTest.tlb type library. A new application is alway created. /// <regsvcs action="create" assembly="myTest.dll" > /// Uninstall the COM+ application contained in myTest.dll /// <regsvcs action="uninstall" assembly="myTest.dll" > /// [TaskName("regsvcs")] public class RegsvcsTask : ExternalProgramBase { public enum ActionTypes { findorcreate, create, uninstall}; StringBuilder _argumentBuilder = null; string _appname = null; string _tlb = null; bool _extlb = false; bool _noreconfig = false; bool _compOnly = false; string _parname = null; string _assemblyName = null; ActionTypes _action = ActionTypes.findorcreate; #region Task Attributes /// /// Defines the action to take with the assembly. Supported actions are: findorcreate (the default), create, or uninstall. /// [TaskAttribute("action")] public ActionTypes ActionType { get { return _action; } set { _action = value; }} /// Specifies the type library file to install. [TaskAttribute("tlb")] public string TypeLibrary { get { return _tlb; } set { _tlb = value; } } /// Uses an existing type library. [TaskAttribute("extlb")] [BooleanValidator] public bool ExistingTypeLibrary { get { return _extlb; } set { _extlb = value; } } /// Do not reconfigure an existing target application. [TaskAttribute("noreconfig")] [BooleanValidator] public bool NoReconfig { get { return _noreconfig; } set {_noreconfig = value; } } /// Configures components only; ignores methods and interfaces. [TaskAttribute("componly")] [BooleanValidator] public bool CompOnly { get { return _compOnly; } set { _compOnly = value; } } /// Specifies the name of the COM+ 1.0 application to either find or create. [TaskAttribute("appname")] public string AppName { get { return _appname; } set {_appname = value; } } /// Specifies the name or id of the COM+ 1.0 application to either find or create. [TaskAttribute("parname")] public string TargetPartitionName { get { return _parname; } set { _parname = value; } } /// The source assembly file. /// The assembly must be signed with a strong name. [TaskAttribute("assembly", Required=true)] public string AssemblyName { get { return _assemblyName; } set { _assemblyName = value; } } #endregion public override string ProgramArguments { get { return _argumentBuilder.ToString(); } } public override string ProgramFileName { get {return "regsvcs"; } } // Process a single file or file group protected override void ExecuteTask() { _argumentBuilder = new StringBuilder(); switch (ActionType) { case ActionTypes.create: _argumentBuilder.Append("/c "); Log(Level.Info,"Creating COM+ application {0}", AssemblyName); break; case ActionTypes.findorcreate: _argumentBuilder.Append("/fc "); Log(Level.Info,"Finding or creating COM+ application {0}", AssemblyName); break; case ActionTypes.uninstall: _argumentBuilder.Append("/u "); Log(Level.Info,"Uninstalling COM+ application {0}", AssemblyName); break; } if (TypeLibrary != null) { _argumentBuilder.AppendFormat("/tlb:{0} ", TypeLibrary); } if (ExistingTypeLibrary) { _argumentBuilder.Append("/extlb "); } if (NoReconfig) { _argumentBuilder.Append("/noreconfig"); } if (CompOnly) { _argumentBuilder.Append("/componly "); } if (AppName != null) { _argumentBuilder.AppendFormat("/appname:{0} ", AppName); } if (TargetPartitionName != null) { _argumentBuilder.AppendFormat("/parname:{0} ", TargetPartitionName); } _argumentBuilder.Append("/quiet "); _argumentBuilder.Append(AssemblyName); base.ExecuteTask(); } } }