public static void InstallNuGetPackage(this IProject project, IVsPackageInstallerServices vsPackageInstallerServices, IVsPackageInstaller vsPackageInstaller, IStatusBar StatusBar, string packageName) { try { var version = NugetPackageVersionManager.GetVersionFromCacheForPackage(packageName); if (!String.IsNullOrEmpty(version)) { StatusBar.DisplayMessage(String.Format("Installing Package: {0} {1}...", packageName, version)); try { InstallNugetPackageForSpecifiedVersion(project, vsPackageInstaller, packageName, version); } catch (Exception installException) { StatusBar.DisplayMessage(String.Format("When attempting to install version {0} of the package {1}, the following error occured: {2}.. Going to now try installing the latest version of Package ...", version, packageName, installException.Message)); // There was a problem installing the specified version of the package. Try the installing the latest available package from the source. InstallLatestNugetPackage(project, vsPackageInstallerServices, vsPackageInstaller, packageName); } } else { StatusBar.DisplayMessage(String.Format("Installing the latest version of Package: {0}...", packageName)); InstallLatestNugetPackage(project, vsPackageInstallerServices, vsPackageInstaller, packageName); } StatusBar.DisplayMessage(""); } catch (Exception ex) { throw new Exception(String.Format("NuGet Package {0} cannot be installed ({1}).", packageName, ex.Message), ex); } }
public static void InstallNugetPackageForSpecifiedVersion(this IProject project, IVsPackageInstallerServices vsPackageInstallerServices, IVsPackageInstaller vsPackageInstaller, IStatusBar StatusBar, string packageName, string version) { try { StatusBar.DisplayMessage(String.Format("Installing Package: {0} {1}...", packageName, version)); try { InstallNugetPackageForSpecifiedVersion(project, vsPackageInstaller, packageName, version); } catch (Exception installException) { StatusBar.DisplayMessage(String.Format("When attempting to install version {0} of the package {1}, the following error occured: {2}.. Going to now try installing the latest version of Package ...", version, packageName, installException.Message)); } } catch (Exception ex) { throw new Exception(String.Format("NuGet Package {0} cannot be installed ({1}).", packageName, ex.Message), ex); } finally { StatusBar.DisplayMessage(""); } }
public static void InstallNuGetPackage(this IProject project, IVsPackageInstallerServices vsPackageInstallerServices, IVsPackageInstaller vsPackageInstaller, IStatusBar StatusBar, string packageName, string targetNsbVersion) { string packageId; int? majorVersion; GetPackageIdAndMajorVersion(packageName, targetNsbVersion, out packageId, out majorVersion); try { var version = NugetPackageVersionManager.GetVersionFromCacheForPackage(packageId, majorVersion); if (!String.IsNullOrEmpty(version)) { StatusBar.DisplayMessage(String.Format("Installing Package: {0} {1}...", packageId, version)); try { InstallNugetPackageForSpecifiedVersion(project, vsPackageInstaller, packageId, version); } catch (Exception installException) { StatusBar.DisplayMessage(String.Format("When attempting to install version {0} of the package {1}, the following error occured: {2}.. Going to now try installing the latest version of Package ...", version, packageId, installException.Message)); // There was a problem installing the specified version of the package. Try the installing the latest available package from the source. InstallLatestNugetPackage(project, vsPackageInstallerServices, vsPackageInstaller, packageId, majorVersion); } } else { StatusBar.DisplayMessage(String.Format("Installing the latest version of Package: {0}...", packageId)); InstallLatestNugetPackage(project, vsPackageInstallerServices, vsPackageInstaller, packageId, majorVersion); } } catch (Exception ex) { throw new Exception(String.Format("NuGet Package {0} cannot be installed ({1}).", packageId, ex.Message), ex); } finally { StatusBar.DisplayMessage(""); } }