コード例 #1
0
            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);
                }
            }
コード例 #2
0
            public override Task OnPackageInstalledAsync(PackageIdentity package, NuGetFramework projectFramework, PackageReaderBase packageReader, string installPath)
            {
                var packageConfiguration = Owner.packageConfiguration;
                var taggedPackage        = IsTaggedPackage(packageReader);
                var relativePath         = Owner.GetRelativePath(installPath);

                if (!packageConfiguration.Packages.Contains(package.Id))
                {
                    packageConfiguration.Packages.Add(package.Id, package.Version.ToString());
                }
                else
                {
                    packageConfiguration.Packages[package.Id].Version = package.Version.ToString();
                }

                Owner.AddContentFolders(installPath, ExtensionsDirectory);
                Owner.RegisterLibraryFolders(packageReader, relativePath);
                Owner.RegisterAssemblyLocations(packageReader, installPath, relativePath, 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);
                        using var pivotReader = pivotPackage.GetReader();
                        Owner.RegisterLibraryFolders(pivotReader, relativePath);
                        Owner.RegisterAssemblyLocations(pivotReader, installPath, relativePath, false);
                    }
                }

                var assemblyLocations = GetCompatibleAssemblyReferences(Owner.bootstrapperFramework, packageReader);

                Owner.RegisterAssemblyLocations(assemblyLocations, installPath, relativePath, taggedPackage);
                packageConfiguration.Save();

                if (package.Id == Owner.bootstrapperPackageId && package.Version > Owner.bootstrapperVersion)
                {
                    var bootstrapperFileName = Path.GetFileName(Owner.bootstrapperExePath);
                    var bootstrapperFile     = packageReader.GetFiles().FirstOrDefault(file => Path.GetFileName(file).Equals(bootstrapperFileName, StringComparison.OrdinalIgnoreCase));
                    if (bootstrapperFile == null)
                    {
                        throw new InvalidOperationException(Resources.BootstrapperMissingFromPackage);
                    }

                    var backupExePath = Owner.bootstrapperExePath + OldExtension;
                    File.Move(Owner.bootstrapperExePath, backupExePath);
                    UpdateFile(Owner.bootstrapperExePath, packageReader, bootstrapperFile);
                }

                return(base.OnPackageInstalledAsync(package, projectFramework, packageReader, installPath));
            }
コード例 #3
0
            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);
            }