I'm trying to get the list of installed NuGet packages in my ASP.NET MVC application and I'm using NuGet.VisualStudio like this:
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);
}
For some reasons I've put above code in Global.asax.cs
file, but componentModel
is always null.
Any idea what's wrong with it?