下面我們來實現程序集的安裝,代碼如下:
/// <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);
}