internal void InstallPackage(IPackageRepository repository, Project project, string packageId, Version version, bool ignoreDependencies) { if (project == null) { throw new ArgumentNullException("project"); } IVsPackageManager packageManager = _packageManagerFactory.CreatePackageManager(repository); 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, NullLogger.Instance); }; try { projectManager.PackageReferenceAdded += addedHandler; packageManager.PackageInstalled += installedHandler; packageManager.InstallPackage(projectManager, packageId, version, ignoreDependencies, NullLogger.Instance); } finally { projectManager.PackageReferenceAdded -= addedHandler; packageManager.PackageInstalled -= installedHandler; } }
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; } } }
private void OnPackageInstalled(object sender, PackageOperationEventArgs e) { _scriptExecutor.ExecuteInitScript(e.InstallPath, e.Package, this); }
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; } } }