Install nuget package progrmmatically

Topics: General
Mar 31, 2015 at 11:14 PM
I'm working on an item template that when added will also install a specific Nuget package. I found this blog post showing how to install a package however it requires you to pass PackageManager the location where the package is to be installed. I'm just trying to install it in the default location for the solution. Is there anything I can pass the constructor in order to do this?
Apr 1, 2015 at 3:32 AM
Edited Apr 1, 2015 at 3:33 AM
After doing some additional digging I finally figured it out. Turns out Nuget.Core was not what I was looking for. Turns out I needed the IVsPackageInstaller interface from the Nuget Extensibility APIs. For anyone interested here's how I was able to install the package:
private bool InstallTemplateBuilderPackage(EnvDTE.Project project)
      bool installedPkg = true;
            var componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));
            IVsPackageInstallerServices installerServices = componentModel.GetService<IVsPackageInstallerServices>();

            if (!installerServices.IsPackageInstalled(project, "TemplateBuilder"))
                  var installer = componentModel.GetService<IVsPackageInstaller>();
                  installer.InstallPackage("All", project, "TemplateBuilder", (System.Version)null, false);

      catch (Exception ex)
            installedPkg = false;

            // Log the failure

      return installedPkg;
Marked as answer by RandomlyKnighted on 3/31/2015 at 7:32 PM