コード例 #1
0
        public async Task Do(string package, string rootPath)
        {
            if (rootPath == null)
            {
                rootPath = Directory.GetCurrentDirectory();
            }

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

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

            var settings = Settings.LoadDefaultSettings(rootPath, null, new MachineWideSettings());
            var project  = new ProjectBazel(rootPath, null, false);
            var sourceRepositoryProvider = new SourceRepositoryProvider(settings, providers);
            var solutionManager          = new BazelSolutionManager(project, rootPath);
            var deleteManager            = new DeleteOnRestart();
            var packageManager           = new NuGetPackageManager(sourceRepositoryProvider, settings, solutionManager, deleteManager)
            {
                PackagesFolderNuGetProject = project,
            };

            var projectContext   = new ProjectContext();
            var uninstallContext = new UninstallationContext(true, true);

            await packageManager.UninstallPackageAsync(packageManager.PackagesFolderNuGetProject,
                                                       package, uninstallContext, projectContext,
                                                       CancellationToken.None);
        }
コード例 #2
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);
        }
コード例 #3
0
 public BazelSolutionManager(ProjectBazel project, string rootPath)
 {
     _project          = project;
     SolutionDirectory = rootPath;
 }