private PackageFragmentValidationResult DoInstall() { using (var transactionScope = TransactionsFacade.Create(true, TimeSpan.FromMinutes(30.0))) { string uninstallFilename = Path.Combine(this.PackageInstallDirectory, PackageSystemSettings.UninstallFilename); Exception installException = null; XElement uninstallElements = new XElement(XmlUtils.GetXName(PackageSystemSettings.XmlNamespace, PackageSystemSettings.PackageFragmentUninstallersElementName)); try { foreach (var kvp in _packageFramentInstallers) { List <XElement> uninstallInformation = kvp.Key.Install().ToList(); if (this.CanBeUninstalled) { XElement uninstallElement = new XElement(XmlUtils.GetXName(PackageSystemSettings.XmlNamespace, PackageSystemSettings. PackageFragmentUninstallersAddElementName)); uninstallElement.Add(new XAttribute(PackageSystemSettings.UninstallerTypeAttributeName, TypeManager.SerializeType(kvp.Value))); uninstallElement.Add(uninstallInformation); uninstallElements.Add(uninstallElement); } } } catch (Exception ex) { installException = ex; LoggingService.LogError("Package installation failed", ex); } finally { if (this.CanBeUninstalled) { XDocument doc = new XDocument( new XElement( XmlUtils.GetXName(PackageSystemSettings.XmlNamespace, PackageSystemSettings.PackageInstallerElementName), uninstallElements)); doc.SaveToFile(uninstallFilename); } } if (installException != null) { if (this.CanBeUninstalled) { IPackageUninstaller packageUninstaller = this.PackageInstallerUninstallerFactory.CreateUninstaller( this.ZipFilename, uninstallFilename, this.PackageInstallDirectory, TempDirectoryFacade. CreateTempDirectory(), this.FlushOnCompletion, this.ReloadConsoleOnCompletion, false, this.PackageInformation); List <PackageFragmentValidationResult> validationResult = null; try { validationResult = packageUninstaller.Validate().ToList(); } catch (Exception ex) { return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, ex)); } if (validationResult.Count == 0) { try { packageUninstaller.Uninstall(SystemLockingType.None); } catch (Exception ex) { return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, ex)); } } else { LoggingService.LogError(LogTitle, "Failed to perform installation rollback."); foreach (var valResult in validationResult) { if (valResult.Exception != null) { LoggingService.LogError(LogTitle, new InvalidOperationException(valResult.Message ?? string.Empty, valResult.Exception)); } else { LoggingService.LogWarning(LogTitle, valResult.Message); } } return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, "Could not perform installation rollback. The details are in the log.") { InnerResult = validationResult }); } } return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, installException)); } transactionScope.Complete(); } return(null); }