当前位置: 首页>>代码示例>>C#>>正文


C# InstallerCollection类代码示例

本文整理汇总了C#中System.Configuration.Install.InstallerCollection的典型用法代码示例。如果您正苦于以下问题:C# InstallerCollection类的具体用法?C# InstallerCollection怎么用?C# InstallerCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


InstallerCollection类属于System.Configuration.Install命名空间,在下文中一共展示了InstallerCollection类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

//引入命名空间
using System;
using System.ComponentModel;
using System.Collections;
using System.Configuration.Install;
using System.IO;

public class InstallerCollection_Add
{
   public static void Main(String[] args)
   {
      ArrayList options = new ArrayList();
      String myOption;
      bool toUnInstall = false;
      bool toPrintHelp = false;
      TransactedInstaller myTransactedInstaller = new TransactedInstaller();
      AssemblyInstaller myAssemblyInstaller;
      InstallContext myInstallContext;

      try
      {
         for(int i = 0; i < args.Length; i++)
         {
            // Process the arguments.
            if(args[i].StartsWith("/") || args[i].StartsWith("-"))
            {
               myOption = args[i].Substring(1);
               // Determine whether the option is to 'uninstall' a assembly.
               if(String.Compare(myOption, "u", true) == 0 ||
                  String.Compare(myOption, "uninstall", true) == 0)
               {
                  toUnInstall = true;
                  continue;
               }
               // Determine whether the option is for printing help information.
               if(String.Compare(myOption, "?", true) == 0 ||
                  String.Compare(myOption, "help", true) == 0)
               {
                  toPrintHelp = true;
                  continue;
               }
               // Add the option encountered to the list of all options
               // encountered for the current assembly.
               options.Add(myOption);
            }
            else
            {
               // Determine whether the assembly file exists.
               if(!File.Exists(args[i]))
               {
                  // If assembly file doesn't exist then print error.
                  Console.WriteLine(" Error : {0} - Assembly file doesn't exist.", args[i]);
                  return;
               }
               // Create an instance of 'AssemblyInstaller' that installs the given assembly.
               myAssemblyInstaller = new AssemblyInstaller(args[i],
                  (string[]) options.ToArray(typeof(string)));
               // Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
               myTransactedInstaller.Installers.Add(myAssemblyInstaller);
            }
         }
         // If user requested help or didn't provide any assemblies to install
         // then print help message.
         if(toPrintHelp || myTransactedInstaller.Installers.Count == 0)
         {
            PrintHelpMessage();
            return;
         }

         // Create an instance of 'InstallContext' with the options specified.
         myInstallContext =
            new InstallContext("Install.log",
            (string[]) options.ToArray(typeof(string)));
         myTransactedInstaller.Context = myInstallContext;

         // Install or Uninstall an assembly depending on the option provided.
         if(!toUnInstall)
            myTransactedInstaller.Install(new Hashtable());
         else
            myTransactedInstaller.Uninstall(null);
      }
      catch(Exception e)
      {
         Console.WriteLine(" Exception raised : {0}", e.Message);
      }
   }

   public static void PrintHelpMessage()
   {
      Console.WriteLine("Usage : InstallerCollection_Add [/u | /uninstall] [option [...]] assembly" +
         "[[option [...]] assembly] [...]]");
      Console.WriteLine("InstallerCollection_Add executes the installers in each of" +
         " the given assembly. If /u or /uninstall option" +
         " is given it uninstalls the assemblies.");
   }
}
开发者ID:.NET开发者,项目名称:System.Configuration.Install,代码行数:96,代码来源:InstallerCollection


注:本文中的System.Configuration.Install.InstallerCollection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。