示例#1
0
        void InstallPackage(string source, Project project, string packageId, string version, bool includePrerelease, bool ignoreDependencies)
        {
            Runtime.RunInMainThread(delegate {
                var repositoryProvider = SourceRepositoryProviderFactory.CreateSourceRepositoryProvider();
                var repository         = repositoryProvider.CreateRepository(new PackageSource(source));

                var action = new InstallNuGetPackageAction(
                    new [] { repository },
                    PackageManagementServices.Workspace.GetSolutionManager(project.ParentSolution),
                    new DotNetProjectProxy((DotNetProject)project),
                    new NuGetProjectContext())
                {
                    PackageId          = packageId,
                    Version            = string.IsNullOrEmpty(version) ? null : new NuGetVersion(version),
                    IncludePrerelease  = includePrerelease,
                    IgnoreDependencies = ignoreDependencies,
                };

                var message = ProgressMonitorStatusMessageFactory.CreateInstallingSinglePackageMessage(packageId);
                PackageManagementServices.BackgroundPackageActionRunner.Run(message, action);
            });
        }