本文整理汇总了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.");
}
}