Esempio n. 1
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;
                    packageManager.InstallPackage(
                        projectManager,
                        packageId,
                        version,
                        ignoreDependencies,
                        allowPrereleaseVersions: true,
                        skipAssemblyReferences: skipAssemblyReferences,
                        logger: NullLogger.Instance);
                }
                finally
                {
                    packageManager.BindingRedirectEnabled = oldBindingRedirectValue;
                    projectManager.PackageReferenceAdded -= addedHandler;
                    packageManager.PackageInstalled      -= installedHandler;
                }
            }
        }
Esempio n. 2
0
 private void SaveExpandedNodes()
 {
     // remember which nodes are currently open so that we can keep them open after the operation
     _expandedNodesDisposable = _vsCommonOperations.SaveSolutionExplorerNodeStates(SolutionManager);
 }
        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;
                }
            }
        }