Exemple #1
0
        public async Task Do(string package, string version, string rootPath, string mainFile, bool skipSha256)
        {
            if (rootPath == null)
            {
                rootPath = Directory.GetCurrentDirectory();
            }

            var logger    = new Logger();
            var providers = new List <Lazy <INuGetResourceProvider> >();

            providers.AddRange(Repository.Provider.GetCoreV3());  // Add v3 API support
            var packageSource           = new PackageSource("https://api.nuget.org/v3/index.json");
            var sourceRepository        = new SourceRepository(packageSource, providers);
            var packageMetadataResource = await sourceRepository.GetResourceAsync <PackageMetadataResource>();

            var verParsed = NuGetVersion.Parse(version);
            var identity  = new NuGet.Packaging.Core.PackageIdentity(package, verParsed);
            var content   = new SourceCacheContext();
            var found     = await packageMetadataResource.GetMetadataAsync(identity, content, logger, CancellationToken.None);

            var settings = Settings.LoadDefaultSettings(rootPath, null, new MachineWideSettings());
            var project  = new ProjectBazel(rootPath, mainFile, skipSha256);
            var sourceRepositoryProvider = new SourceRepositoryProvider(settings, providers);
            var packageManager           = new NuGetPackageManager(sourceRepositoryProvider, settings, rootPath)
            {
                PackagesFolderNuGetProject = project
            };

            const bool allowPrereleaseVersions = false;
            const bool allowUnlisted           = false;
            var        resolutionContext       = new ResolutionContext(
                DependencyBehavior.HighestMinor, allowPrereleaseVersions, allowUnlisted, VersionConstraints.None);

            var projectContext = new ProjectContext();

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

            project.NuGetProjectActions = actions;

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

            NuGetPackageManager.ClearDirectInstall(projectContext);
        }
Exemple #2
0
        public async Task DoWithProject(string nugetSource, string package, string version, ProjectBazelManipulator project, bool lowest)
        {
            var logger    = new Logger();
            var providers = new List <Lazy <INuGetResourceProvider> >();

            providers.AddRange(Repository.Provider.GetCoreV3());  // Add v3 API support
            var packageSource           = new PackageSource(nugetSource);
            var sourceRepository        = new SourceRepository(packageSource, providers);
            var packageMetadataResource = await sourceRepository.GetResourceAsync <PackageMetadataResource>();

            var verParsed = NuGetVersion.Parse(version);
            var identity  = new NuGet.Packaging.Core.PackageIdentity(package, verParsed);
            var content   = new SourceCacheContext();
            var found     = await packageMetadataResource.GetMetadataAsync(identity, content, logger, CancellationToken.None);

            //var settings = Settings.LoadDefaultSettings(project.ProjectConfig.RootPath, null, new MachineWideSettings());
            var settings = Settings.LoadDefaultSettings(project.ProjectConfig.RootPath, null, null);
            var sourceRepositoryProvider = new SourceRepositoryProvider(settings, providers);
            var packageManager           = new NuGetPackageManager(sourceRepositoryProvider, settings, project.ProjectConfig.RootPath)
            {
                PackagesFolderNuGetProject = project
            };

            const bool allowPrereleaseVersions = true;
            const bool allowUnlisted           = false;
            var        resolutionContext       = new ResolutionContext(
                lowest ? DependencyBehavior.Lowest : DependencyBehavior.HighestMinor, allowPrereleaseVersions, allowUnlisted, VersionConstraints.None);

            var projectContext = new ProjectContext(settings);

            var actions = await packageManager.PreviewInstallPackageAsync(packageManager.PackagesFolderNuGetProject,
                                                                          identity, resolutionContext, projectContext, sourceRepository,
                                                                          sourceRepositoryProvider.GetRepositories(),
                                                                          CancellationToken.None);

            project.NuGetProjectActions = actions;

            await packageManager.InstallPackageAsync(packageManager.PackagesFolderNuGetProject,
                                                     identity, resolutionContext, projectContext, sourceRepository,
                                                     sourceRepositoryProvider.GetRepositories(),
                                                     CancellationToken.None);

            NuGetPackageManager.ClearDirectInstall(projectContext);
        }
Exemple #3
0
        public async Task DoWithProject(string package, string version, ProjectBazelManipulator project, bool lowest)
        {
            var logger    = new Logger();
            var providers = new List <Lazy <INuGetResourceProvider> >();

            providers.AddRange(Repository.Provider.GetCoreV3());  // Add v3 API support
            var packageSource           = new PackageSource("https://api.nuget.org/v3/index.json");
            var sourceRepository        = new SourceRepository(packageSource, providers);
            var packageMetadataResource = await sourceRepository.GetResourceAsync <PackageMetadataResource>();

            var verParsed = NuGetVersion.Parse(version);
            var identity  = new NuGet.Packaging.Core.PackageIdentity(package, verParsed);
            var content   = new SourceCacheContext();
            var found     = await packageMetadataResource.GetMetadataAsync(identity, content, logger, CancellationToken.None);

            var settings = Settings.LoadDefaultSettings(project.ProjectConfig.RootPath, null, new MachineWideSettings());
            var sourceRepositoryProvider = new SourceRepositoryProvider(settings, providers);
            var packageManager           = new NuGetPackageManager(sourceRepositoryProvider, settings, project.ProjectConfig.RootPath)
            {
                PackagesFolderNuGetProject = project
            };

            const bool allowPrereleaseVersions = true;
            const bool allowUnlisted           = false;
            var        resolutionContext       = new ResolutionContext(
                lowest ? DependencyBehavior.Lowest : DependencyBehavior.HighestMinor, allowPrereleaseVersions, allowUnlisted, VersionConstraints.None);

            var projectContext = new ProjectContext(settings);

            var projects = new ProjectBazelManipulator[] { project };
            var actions  = await packageManager.PreviewUpdatePackagesAsync(identity, projects, resolutionContext, projectContext,
                                                                           new SourceRepository[] { sourceRepository },
                                                                           Array.Empty <SourceRepository>(), // This is a list of secondary source respositories, probably empty
                                                                           CancellationToken.None);

            project.NuGetProjectActions = actions;

            var sourceCacheContext = new SourceCacheContext();
            await packageManager.ExecuteNuGetProjectActionsAsync(project, actions, projectContext, sourceCacheContext,
                                                                 CancellationToken.None);

            NuGetPackageManager.ClearDirectInstall(projectContext);
        }