下面我们来实现程序集的安装,代码如下:
/// <summary>
/// 程序集安装与卸载
/// </summary>
/// <param name="assemblyPath">程序集路径</param>
/// <param name="isInstall">是否安装(若为False则为卸载)</param>
public void AssemblyInstall(string assemblyPath, bool isInstall) {
System.Configuration.Install.TransactedInstaller transactedInstaller = new System.Configuration.Install.TransactedInstaller();
System.Configuration.Install.AssemblyInstaller assemblyInstaller = new System.Configuration.Install.AssemblyInstaller(assemblyPath, null);
transactedInstaller.Installers.Add(assemblyInstaller);
if (isInstall)
transactedInstaller.Install(null);
else
transactedInstaller.Uninstall(null);
}