Example #1
0
 static void Main(string[] args)
 {
     // Register a private assembly.
     RegistrationHelper rh = new RegistrationHelper();
     try
     {
         string comPlusAppName = "NewComPlusApp";
         string typeLibName = "FooServicedComp.tlb";
         rh.InstallAssembly("FooServicedComp.dll",
             ref comPlusAppName,
             ref typeLibName,
             InstallationFlagsFindOrCreateTargetApplication);
     }
     catch(RegistrationException rhex)
     {
         Console.WriteLine(rhex.Message);
     }
 }
 /// <summary>
 /// When overridden in a derived class, performs the installation.
 /// </summary>
 /// <param name="stateSaver">An <see cref="T:System.Collections.IDictionary"/> used to save information needed to perform a commit, rollback, or uninstall operation.</param>
 public override void Install(IDictionary stateSaver)
 {
     base.Install(stateSaver);
     string appID = string.Empty;
     string typeLib = string.Empty;
     // Get the location of the current assembly
     string assemblyLocation = GetType().Assembly.Location;
     // Install the application
     try
     {
         RegistrationHelper regHelper = new RegistrationHelper();
         regHelper.InstallAssembly(assemblyLocation, ref appID, ref typeLib, InstallationFlags.FindOrCreateTargetApplication);
         // Save the state - you will need this for the uninstall
         stateSaver.Add("AppID", appID);
         stateSaver.Add("Assembly", assemblyLocation);
     }
     catch (Exception ex)
     {
         throw new InstallException("Error during registration of " + GetType().Assembly.FullName, ex);
     }
 }