public void InstallPackage(LegacyNuGet.IPackageRepository repository, Project project, string packageId, string version, bool ignoreDependencies, bool skipAssemblyReferences) { // It would be really difficult for anyone to use this method throw new NotSupportedException(); }
/// <summary> /// Installs one or more packages into the specified project. /// </summary> /// <param name="packageInstaller">The package installer service that performs the actual package installation.</param> /// <param name="project">The target project for installation.</param> /// <param name="configuration">The packages to install, where to install them from, and additional options for their installation.</param> /// <param name="repositorySettings">The repository settings for the packages being installed.</param> /// <param name="warningHandler">An action that accepts a warning message and presents it to the user, allowing execution to continue.</param> /// <param name="errorHandler">An action that accepts an error message and presents it to the user, allowing execution to continue.</param> internal void PerformPackageInstall( IVsPackageInstaller packageInstaller, Project project, PreinstalledPackageConfiguration configuration, Action <string> warningHandler, Action <string> errorHandler) { string repositoryPath = configuration.RepositoryPath; var failedPackageErrors = new List <string>(); LegacyNuGet.IPackageRepository repository = configuration.IsPreunzipped ? (LegacyNuGet.IPackageRepository) new LegacyNuGet.UnzippedPackageRepository(repositoryPath) : (LegacyNuGet.IPackageRepository) new LegacyNuGet.LocalPackageRepository(repositoryPath); PreinstalledRepositoryProvider repos = new PreinstalledRepositoryProvider(errorHandler, _sourceProvider); repos.AddFromRepository(repository); // store expanded node state IDictionary <string, ISet <VsHierarchyItem> > expandedNodes = VsHierarchyHelper.GetAllExpandedNodes(_solutionManager); foreach (var package in configuration.Packages) { // Does the project already have this package installed? if (_packageServices.IsPackageInstalled(project, package.Id)) { // If so, is it the right version? if (!_packageServices.IsPackageInstalledEx(project, package.Id, package.Version.ToNormalizedString())) { // No? Raise a warning (likely written to the Output window) and ignore this package. warningHandler(String.Format(VsResources.PreinstalledPackages_VersionConflict, package.Id, package.Version)); } // Yes? Just silently ignore this package! } else { try { if (InfoHandler != null) { InfoHandler(String.Format(CultureInfo.CurrentCulture, VsResources.PreinstalledPackages_PackageInstallStatus, package.Id, package.Version)); } List <PackageIdentity> toInstall = new List <PackageIdentity>(); toInstall.Add(new PackageIdentity(package.Id, package.Version)); // Skip assembly references and disable binding redirections should be done together bool disableBindingRedirects = package.SkipAssemblyReferences; VSAPIProjectContext projectContext = new VSAPIProjectContext(package.SkipAssemblyReferences, disableBindingRedirects); // Old templates have hardcoded non-normalized paths projectContext.PackageExtractionContext.UseLegacyPackageInstallPath = true; // This runs from the UI thread PackageManagementHelpers.RunSync(async() => await _installer.InstallInternal(project, toInstall, repos, projectContext, package.IgnoreDependencies, CancellationToken.None)); } catch (InvalidOperationException exception) { failedPackageErrors.Add(package.Id + "." + package.Version + " : " + exception.Message); } catch (AggregateException aggregateEx) { var ex = aggregateEx.Flatten().InnerExceptions.FirstOrDefault(); if (ex is InvalidOperationException) { failedPackageErrors.Add(package.Id + "." + package.Version + " : " + ex.Message); } else { throw; } } } } if (failedPackageErrors.Any()) { var errorString = new StringBuilder(); errorString.AppendFormat(VsResources.PreinstalledPackages_FailedToInstallPackage, repositoryPath); errorString.AppendLine(); errorString.AppendLine(); errorString.Append(String.Join(Environment.NewLine, failedPackageErrors)); errorHandler(errorString.ToString()); } // RepositorySettings = null in unit tests if (EnvDTEProjectUtility.IsWebSite(project)) { CreateRefreshFilesInBin( project, repositoryPath, configuration.Packages.Where(p => p.SkipAssemblyReferences)); CopyNativeBinariesToBin(project, repositoryPath, configuration.Packages); } // collapse nodes VsHierarchyHelper.CollapseAllNodes(_solutionManager, expandedNodes); }