Using this code:
public void InstallPackage(Project project, string packageId, string version, string packageSource)
{
var componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));
var installer = componentModel.GetService<IVsPackageInstaller>();
installer.InstallPackage(packageSource, project, packageId, version, false);
}
When I try to install EntityFramework 6.1.3
, for example, it simply hangs on the installer.InstallPackage()
line. I've let it run as long as 10 minutes with no response, error, message, or any kind of indicator as to what's happening.
I've tried the following package sources:
- https://nuget.org/api/v2
- null
- Downloading the package and referencing a local repo (e.g. C:\Nuget)
All with the same result.
The same thing happens with every package I tried (Newtonsoft.Json
, Unity
, etc.), so it's not just EntityFramework
.
This is running in VS 2015 and .Net 4.5.1.
I've referenced the NuGet.VisualStudio 2.8.6
package, but I've also tried 2.8.5 and 2.8.3 with no success.
Installing the package manually (through the NuGet package manager UI in Visual Studio) works as expected.
I've also tried the NuGet.CommandLine 2.8.6
package, with the following implementation:
public void InstallPackage(Project project, string packageId, string version, string packageSource)
{
var repo = PackageRepositoryFactory.Default.CreateRepository("https://nuget.org/api/v2");
// Get the package install path
var solutionDirectory = Path.GetDirectoryName(project.DTE.Solution.FullName);
var path = Path.Combine(solutionDirectory, "packages");
// Initialize the package manager
var packageManager = new PackageManager(repo, path);
// Download and unzip the package
packageManager.InstallPackage(packageId, SemanticVersion.Parse(version));
var projectSystem = new MSBuildProjectSystem(project.FullName);
var localRepository = PackageRepositoryFactory.Default.CreateRepository(path);
var pathResolver = new DefaultPackagePathResolver(path);
var projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, repo);
// Add references to project
projectManager.AddPackageReference(packageId, SemanticVersion.Parse(version));
}
That downloads the package successfully, but fails to add the reference to the project with this error:
"The 'AdaptiveTriggerLibrary 1.0.3' package requires NuGet client version '3.0' or above, but the current NuGet version is '2.8.60717.93'."
I'm not sure why it wants the AdaptiveTriggerLibrary 1.0.3
, I assume it's a dependency of EntityFramework
.
I tracked down a 3.1 beta NuGet.exe and referenced that. Turns out that the IProjectSystem
interface was removed from the MSBuildProjectSystem
class - and no alternative is available (that I could find), so I couldn't even get to a state where I could compile with that version. Seems pretty broken.
Any ideas?
All I want is a way for a vsix
to install a nuget package to a project.