'NuGet install-package' from c# code but inside a T4 template

Dec 30, 2011 at 8:45 PM
Edited Dec 30, 2011 at 8:45 PM

Hello,

I'm having the same issue as this: http://nuget.codeplex.com/discussions/246688. To make it short, I need to call the install-package of NuGet from c# code but inside a T4 template.

I tried the code mentioned in the URL, but I'm still having the same exception whatever I do.

 

using (ServiceProvider serviceProvider = new ServiceProvider(this._dte as Microsoft.VisualStudio.OLE.Interop.IServiceProvider))
{
	IComponentModel componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
}

 

or this

IComponentModel componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));
But I got always this exception:

Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.VisualStudio.ComponentModelHost.IComponentModel'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{605AF649-8844-3F09-9982-1258074BE833}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

 

Thanks,

Adrien.

Jan 15, 2012 at 7:50 PM

Do someone know how to install a package from C#, whatever the manner?

Jan 19, 2012 at 11:15 PM

I'm having the same problem but with a VS instance I'm calling from the outside. I know this is beyond the scope of what most people do with nuget, but in my case we're standardizing on nuget and want to run a home-grown utility that goes through several hundred of our web service projects and replace common libraries with nuget references. Any help from previous spikes would be much appreciated.

Jun 3, 2013 at 4:05 PM
Hi did you guys ever solve the problem? I have the same issue within a T4 template....
Feb 5, 2014 at 2:00 PM
I've exactly the same problem. Does someone find any issue?