private void InstallAssemblyIntoGAC(string dllPath) { FileInfo fileInfo = new FileInfo(dllPath); this.DTEInstance.WriteBuildWindow("Installing " + fileInfo.Name + " into Global Assembly Cache."); try { AssemblyCache.InstallAssembly(dllPath, null, AssemblyCommitFlags.Force); } catch { try { // If an error is thrown, then try to uninstall it first! AssemblyCacheUninstallDisposition dis = new AssemblyCacheUninstallDisposition(); AssemblyCache.UninstallAssembly(dllPath, null, out dis); if (dis == AssemblyCacheUninstallDisposition.Uninstalled) { // Now uninstalled, try to reinstall AssemblyCache.InstallAssembly(dllPath, null, AssemblyCommitFlags.Force); } else { this.DTEInstance.WriteBuildWindow("Unable to uninstall/install the assembly " + dllPath + " beacuse: " + dis.ToString()); } } catch { this.DTEInstance.WriteBuildWindow("Unable to uninstall/install the assembly " + dllPath); } } }
/// <summary> /// Installs the assembly with the specified path into Global Assembly Cache. /// </summary> /// <param name="path"></param> private bool InstallAssembly(string path) { bool copyDone = true; FileInfo fileInfo = new FileInfo(path); Log.Verbose("Installing " + fileInfo.Name + " into Global Assembly Cache."); try { AssemblyCache.InstallAssembly(path, null, AssemblyCommitFlags.Force); } catch { // If an error is thrown, then try to uninstall it first! AssemblyCacheUninstallDisposition dis = new AssemblyCacheUninstallDisposition(); AssemblyCache.UninstallAssembly(path, null, out dis); if (dis == AssemblyCacheUninstallDisposition.Uninstalled) { // Now uninstalled, try to reinstall AssemblyCache.InstallAssembly(path, null, AssemblyCommitFlags.Force); } else { copyDone = false; Log.Error("Unable to uninstall/install the assembly " + path + " beacuse: " + dis.ToString()); } } return(copyDone); }