Beispiel #1
0
        public void InstallPackage(
            IProjectManager projectManager,
            string packageId,
            SemanticVersion version,
            bool ignoreDependencies,
            bool allowPrereleaseVersions,
            bool skipAssemblyReferences,
            ILogger logger)
        {
            InitializeLogger(logger, projectManager);

            IPackage package = PackageHelper.ResolvePackage(SourceRepository, LocalRepository, packageId, version, allowPrereleaseVersions);

            if (skipAssemblyReferences)
            {
                package = new SkipAssemblyReferencesPackage(package);
            }

            RunSolutionAction(() =>
            {
                InstallPackage(
                    package,
                    projectManager != null ? projectManager.Project.TargetFramework : null,
                    ignoreDependencies,
                    allowPrereleaseVersions);

                AddPackageReference(projectManager, package, ignoreDependencies, allowPrereleaseVersions);

                AddSolutionPackageConfigEntry(package);
            });

            // Add package to recent repository
            AddPackageToRecentRepository(package);
        }
Beispiel #2
0
        internal void InstallPackage(IPackageRepository repository, Project project, string packageId, SemanticVersion version, bool ignoreDependencies, bool skipAssemblyReferences)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            if (repository == null)
            {
                throw new ArgumentNullException("repository");
            }

            using (_vsCommonOperations.SaveSolutionExplorerNodeStates(_solutionManager))
            {
                IVsPackageManager packageManager = _packageManagerFactory.CreatePackageManager(repository,
                                                                                               useFallbackForDependencies: false);
                IProjectManager projectManager = packageManager.GetProjectManager(project);

                EventHandler<PackageOperationEventArgs> installedHandler = (sender, e) =>
                                                                               {
                                                                                   _scriptExecutor.ExecuteInitScript(
                                                                                       e.InstallPath, e.Package,
                                                                                       NullLogger.Instance);
                                                                               };

                EventHandler<PackageOperationEventArgs> addedHandler = (sender, e) =>
                                                                           {
                                                                               _scriptExecutor.ExecuteScript(
                                                                                   e.InstallPath,
                                                                                   PowerShellScripts.Install,
                                                                                   e.Package,
                                                                                   project,
                                                                                   project.GetTargetFrameworkName(),
                                                                                   NullLogger.Instance);
                                                                           };

                bool oldBindingRedirectValue = packageManager.BindingRedirectEnabled;
                try
                {
                    projectManager.PackageReferenceAdded += addedHandler;
                    packageManager.PackageInstalled += installedHandler;
                    // if skipping assembly references, disable binding redirects too.
                    packageManager.BindingRedirectEnabled = !skipAssemblyReferences;

                    // locate the package to install
                    IPackage package = PackageRepositoryHelper.ResolvePackage(
                        packageManager.SourceRepository,
                        packageManager.LocalRepository,
                        packageId,
                        version,
                        allowPrereleaseVersions: true);

                    if (skipAssemblyReferences)
                    {
                        package = new SkipAssemblyReferencesPackage(package);
                    }

                    // resolve actions
                    var resolver = new ActionResolver()
                    {
                        Logger = NullLogger.Instance,
                        DependencyVersion = packageManager.DependencyVersion,
                        IgnoreDependencies = ignoreDependencies,
                        AllowPrereleaseVersions = true
                    };
                    resolver.AddOperation(PackageAction.Install, package, projectManager);
                    var actions = resolver.ResolveActions();

                    // execute actions
                    var actionExecutor = new ActionExecutor();
                    actionExecutor.Execute(actions);
                }
                finally
                {
                    packageManager.BindingRedirectEnabled = oldBindingRedirectValue;
                    projectManager.PackageReferenceAdded -= addedHandler;
                    packageManager.PackageInstalled -= installedHandler;
                }
            }
        }
        public void InstallPackage(
            IProjectManager projectManager,
            string packageId,
            SemanticVersion version,
            bool ignoreDependencies,
            bool allowPrereleaseVersions,
            bool skipAssemblyReferences,
            ILogger logger)
        {
            try
            {
                InitializeLogger(logger, projectManager);

                IPackage package = PackageRepositoryHelper.ResolvePackage(SourceRepository, LocalRepository, packageId, version, allowPrereleaseVersions);

#if VS14
                var nugetAwareProject = projectManager.Project as INuGetPackageManager;
                if (nugetAwareProject != null)
                {
                    var args = new Dictionary<string, object>();
                    args["DependencyVersion"] = DependencyVersion;
                    args["IgnoreDependencies"] = ignoreDependencies;
                    args["WhatIf"] = WhatIf;
                    args["SourceRepository"] = SourceRepository;
                    args["SharedRepository"] = _sharedRepository;

                    CancellationTokenSource cts = new CancellationTokenSource();
                    var task = nugetAwareProject.InstallPackageAsync(
                        new NuGetPackageMoniker
                        {
                            Id = package.Id,
                            Version = package.Version.ToString()
                        },
                        args,
                        logger: null,
                        progress: null,
                        cancellationToken: cts.Token);
                    task.Wait();

                    return;
                }
#endif
                using (StartInstallOperation(packageId, package.Version.ToString()))
                {
                    if (skipAssemblyReferences)
                    {
                        package = new SkipAssemblyReferencesPackage(package);
                    }

                    RunSolutionAction(() =>
                    {
                        InstallPackage(
                            package,
                            projectManager != null ? projectManager.Project.TargetFramework : null,
                            ignoreDependencies,
                            allowPrereleaseVersions);

                        AddPackageReference(projectManager, package, ignoreDependencies, allowPrereleaseVersions);
                    });
                }
            }
            finally
            {
                ClearLogger(projectManager);
            }
        }
Beispiel #4
0
        public void InstallPackage(
            IProjectManager projectManager,
            string packageId,
            SemanticVersion version,
            bool ignoreDependencies,
            bool allowPrereleaseVersions,
            bool skipAssemblyReferences,
            ILogger logger)
        {
            InitializeLogger(logger, projectManager);

            IPackage package = PackageHelper.ResolvePackage(SourceRepository, LocalRepository, packageId, version, allowPrereleaseVersions);
            if (skipAssemblyReferences)
            {
                package = new SkipAssemblyReferencesPackage(package);
            }

            RunSolutionAction(() =>
            {
                InstallPackage(
                    package,
                    projectManager != null ? projectManager.Project.TargetFramework : null,
                    ignoreDependencies,
                    allowPrereleaseVersions);

                AddPackageReference(projectManager, package, ignoreDependencies, allowPrereleaseVersions);

                AddSolutionPackageConfigEntry(package);
            });
        }
Beispiel #5
0
        public void InstallPackage(
            IProjectManager projectManager,
            string packageId,
            SemanticVersion version,
            bool ignoreDependencies,
            bool allowPrereleaseVersions,
            bool skipAssemblyReferences,
            ILogger logger)
        {
            try
            {
                InitializeLogger(logger, projectManager);

                IPackage package = PackageRepositoryHelper.ResolvePackage(SourceRepository, LocalRepository, packageId, version, allowPrereleaseVersions);
                using (StartInstallOperation(packageId, package.Version.ToString()))
                {
                    if (skipAssemblyReferences)
                    {
                        package = new SkipAssemblyReferencesPackage(package);
                    }

                    RunSolutionAction(() =>
                    {
                        InstallPackage(
                            package,
                            projectManager != null ? projectManager.Project.TargetFramework : null,
                            ignoreDependencies,
                            allowPrereleaseVersions);

                        if (!WhatIf)
                        {
                            AddPackageReference(projectManager, package, ignoreDependencies, allowPrereleaseVersions);
                        }
                    });
                }
            }
            finally
            {
                ClearLogger(projectManager);
            }
        }
        internal void InstallPackage(IPackageRepository repository, Project project, string packageId, SemanticVersion version, bool ignoreDependencies, bool skipAssemblyReferences)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            if (repository == null)
            {
                throw new ArgumentNullException("repository");
            }

            using (_vsCommonOperations.SaveSolutionExplorerNodeStates(_solutionManager))
            {
                IVsPackageManager packageManager = _packageManagerFactory.CreatePackageManager(repository,
                                                                                               useFallbackForDependencies: false);
                IProjectManager projectManager = packageManager.GetProjectManager(project);

                EventHandler <PackageOperationEventArgs> installedHandler = (sender, e) =>
                {
                    _scriptExecutor.ExecuteInitScript(
                        e.InstallPath, e.Package,
                        NullLogger.Instance);
                };

                EventHandler <PackageOperationEventArgs> addedHandler = (sender, e) =>
                {
                    _scriptExecutor.ExecuteScript(
                        e.InstallPath,
                        PowerShellScripts.Install,
                        e.Package,
                        project,
                        project.GetTargetFrameworkName(),
                        NullLogger.Instance);
                };

                bool oldBindingRedirectValue = packageManager.BindingRedirectEnabled;
                try
                {
                    projectManager.PackageReferenceAdded += addedHandler;
                    packageManager.PackageInstalled      += installedHandler;
                    // if skipping assembly references, disable binding redirects too.
                    packageManager.BindingRedirectEnabled = !skipAssemblyReferences;

                    // locate the package to install
                    IPackage package = PackageRepositoryHelper.ResolvePackage(
                        packageManager.SourceRepository,
                        packageManager.LocalRepository,
                        packageId,
                        version,
                        allowPrereleaseVersions: true);

                    if (skipAssemblyReferences)
                    {
                        package = new SkipAssemblyReferencesPackage(package);
                    }

                    // resolve actions
                    var resolver = new ActionResolver()
                    {
                        Logger                  = NullLogger.Instance,
                        DependencyVersion       = packageManager.DependencyVersion,
                        IgnoreDependencies      = ignoreDependencies,
                        AllowPrereleaseVersions = true
                    };
                    resolver.AddOperation(PackageAction.Install, package, projectManager);
                    var actions = resolver.ResolveActions();

                    // execute actions
                    var actionExecutor = new ActionExecutor();
                    actionExecutor.Execute(actions);
                }
                finally
                {
                    packageManager.BindingRedirectEnabled = oldBindingRedirectValue;
                    projectManager.PackageReferenceAdded -= addedHandler;
                    packageManager.PackageInstalled      -= installedHandler;
                }
            }
        }