Exemplo n.º 1
0
        public static async Task UninstallPackage(string packageId, string version, ILogger logger = null)
        {
            if (logger == null)
            {
                logger = new ConsoleNuGetLogger(IoC.Get <IConsole>());
            }

            PackageIdentity identity = new PackageIdentity(packageId, new NuGet.Versioning.NuGetVersion(version));

            List <Lazy <INuGetResourceProvider> > providers = new List <Lazy <INuGetResourceProvider> >();

            providers.AddRange(Repository.Provider.GetCoreV3());  // Add v3 API support

            var settings = NuGet.Configuration.Settings.LoadDefaultSettings(Platform.ReposDirectory, null, new MachineWideSettings(), false, true);

            ISourceRepositoryProvider sourceRepositoryProvider = new SourceRepositoryProvider(settings, providers);  // See part 2

            using (var installedPackageCache = GetCache())
            {
                var project = new AvalonStudioExtensionsFolderProject(GetFramework(), installedPackageCache, Platform.ReposDirectory);

                var packageManager = new NuGetPackageManager(sourceRepositoryProvider, settings, new SolutionManager(), new DeleteOnRestartManager())
                {
                    PackagesFolderNuGetProject = project,
                };

                INuGetProjectContext projectContext = new ProjectContext(logger);

                var uninstallationContext = new UninstallationContext(true, true);

                await packageManager.UninstallPackageAsync(project, packageId, uninstallationContext, projectContext, CancellationToken.None);
            }
        }
Exemplo n.º 2
0
        public static async Task InstallPackage(string packageId, string version, ILogger logger = null, int chmodFileMode = DefaultFilePermissions)
        {
            if (logger == null)
            {
                logger = new ConsoleNuGetLogger(IoC.Get <IConsole>());
            }

            PackageIdentity identity = new PackageIdentity(packageId, new NuGet.Versioning.NuGetVersion(version));

            var settings = NuGet.Configuration.Settings.LoadDefaultSettings(Platform.ReposDirectory, null, new MachineWideSettings(), false, true);

            ISourceRepositoryProvider sourceRepositoryProvider = new SourceRepositoryProvider(settings, s_providers);  // See part 2

            using (var installedPackageCache = GetCache())
            {
                var project = new AvalonStudioExtensionsFolderProject(GetFramework(), installedPackageCache, Platform.ReposDirectory);

                if (!project.PackageExists(identity))
                {
                    var packageManager = new NuGetPackageManager(sourceRepositoryProvider, settings, Platform.ReposDirectory)
                    {
                        PackagesFolderNuGetProject = project,
                    };

                    bool allowPrereleaseVersions = true;
                    bool allowUnlisted           = false;

                    ResolutionContext resolutionContext = new ResolutionContext(
                        DependencyBehavior.Lowest, allowPrereleaseVersions, allowUnlisted, VersionConstraints.None);

                    INuGetProjectContext projectContext = new ProjectContext(logger);

                    await packageManager.InstallPackageAsync(packageManager.PackagesFolderNuGetProject,
                                                             identity, resolutionContext, projectContext, s_sourceRepositories,
                                                             Array.Empty <SourceRepository>(), // This is a list of secondary source respositories, probably empty
                                                             CancellationToken.None);

                    var packageDir = GetPackageDirectory(identity);

                    var files = Directory.EnumerateFiles(packageDir, "*.*", SearchOption.AllDirectories);

                    if (Platform.PlatformIdentifier != Platforms.PlatformID.Win32NT)
                    {
                        logger.LogInformation("Applying file attributes.");

                        foreach (var file in files)
                        {
                            Platform.Chmod(file, chmodFileMode);
                        }
                    }

                    await LoadAssetsFromFilesAsync(packageId, version, files);
                }
                else
                {
                    logger.LogInformation("Package is already installed.");
                }
            }
        }
Exemplo n.º 3
0
        private static string GetPackageDirectory(PackageIdentity identity)
        {
            string result = string.Empty;

            using (var installedPackageCache = GetCache())
            {
                var project = new AvalonStudioExtensionsFolderProject(GetFramework(), installedPackageCache, Platform.ReposDirectory);

                result = project.GetInstalledPath(identity);
            }

            return(result);
        }