public override async Task <bool> OnPackageInstallingAsync(PackageIdentity package, NuGetFramework projectFramework, PackageReaderBase packageReader, string installPath) { var entryPoint = package.Id + BonsaiExtension; var nearestFrameworkGroup = packageReader.GetContentItems().GetNearest(Owner.bootstrapperFramework); var executablePackage = nearestFrameworkGroup?.Items.Any(file => PathUtility.GetRelativePath(ContentFolder, file) == entryPoint); if (executablePackage.GetValueOrDefault()) { var packageFolder = Path.GetDirectoryName(packageReader.GetNuspecFile()); var resolver = new VersionFolderPathResolver(packageFolder, isLowercase: false); var nupkgFileName = resolver.GetPackageFileName(package.Id, package.Version); var nupkgFilePath = Path.Combine(packageFolder, nupkgFileName); var localPackage = Owner.galleryRepository.GetLocalPackage(package); if (localPackage == null) { var targetFilePath = Path.Combine(Owner.galleryRepository.PackageSource.Source, Path.GetFileName(nupkgFileName)); PathUtility.EnsureParentDirectory(targetFilePath); File.Copy(nupkgFilePath, targetFilePath); } return(false); } else { var pivots = OverlayHelper.FindPivots(packageReader, installPath).ToArray(); if (pivots.Length > 0) { PathUtility.EnsureParentDirectory(Path.Combine(installPath, package.Id)); var overlayVersion = OverlayHelper.FindOverlayVersion(packageReader); var overlayManager = OverlayHelper.CreateOverlayManager(Owner.packageManager, installPath); overlayManager.Logger = Owner.packageManager.Logger; try { foreach (var pivot in pivots) { var pivotIdentity = new PackageIdentity(pivot, overlayVersion); var pivotPackage = await overlayManager.InstallPackageAsync(pivotIdentity, projectFramework, ignoreDependencies : true, CancellationToken.None); if (pivotPackage == null) { throw new InvalidOperationException(string.Format("The package '{0}' could not be found.", pivot)); } } } catch { foreach (var pivot in pivots) { var pivotIdentity = new PackageIdentity(pivot, overlayVersion); await overlayManager.UninstallPackageAsync(pivotIdentity, projectFramework, removeDependencies : false, CancellationToken.None); } throw; } } return(true); } }
public override async Task <bool> OnPackageUninstallingAsync(PackageIdentity package, NuGetFramework projectFramework, PackageReaderBase packageReader, string installPath) { var taggedPackage = IsTaggedPackage(packageReader); var relativePath = Owner.GetRelativePath(installPath); Owner.packageConfiguration.Packages.Remove(package.Id); Owner.RemoveContentFolders(packageReader, installPath, ExtensionsDirectory); Owner.RemoveLibraryFolders(packageReader, relativePath); Owner.RemoveAssemblyLocations(packageReader, installPath, false); var pivots = OverlayHelper.FindPivots(packageReader, installPath).ToArray(); if (pivots.Length > 0) { var overlayManager = OverlayHelper.CreateOverlayManager(Owner.packageManager, installPath); foreach (var pivot in pivots) { var pivotPackage = overlayManager.LocalRepository.FindLocalPackage(pivot); if (pivotPackage != null) { using var pivotReader = pivotPackage.GetReader(); Owner.RemoveLibraryFolders(pivotReader, relativePath); Owner.RemoveAssemblyLocations(pivotReader, installPath, false); } } } var assemblyLocations = GetCompatibleAssemblyReferences(Owner.bootstrapperFramework, packageReader); Owner.RemoveAssemblyLocations(assemblyLocations, installPath, taggedPackage); Owner.packageConfiguration.Save(); if (pivots.Length > 0) { var overlayVersion = OverlayHelper.FindOverlayVersion(packageReader); var overlayManager = OverlayHelper.CreateOverlayManager(Owner.packageManager, installPath); overlayManager.Logger = Owner.packageManager.Logger; foreach (var pivot in pivots) { var pivotIdentity = new PackageIdentity(pivot, overlayVersion); await overlayManager.UninstallPackageAsync(pivotIdentity, projectFramework, removeDependencies : false, CancellationToken.None); } } return(true); }