1

The following code is raising NullReferenceException ("Object reference not set to an instance of an object.") on Visual Studio 2015, NuGet.VisualStudio v3.3).

try { this.PackageInstaller.InstallPackage(packageSource, project, packageId, version, ignoreDependencies); } catch (Exception ex) { string error = string.Format(CultureInfo.CurrentCulture, Properties.Resources.RES_Error_InstallingNuGetPackage, packageId, project.Name); throw new NuGetServiceException(error, ex); } 

The PackageInstaller is an instance of NuGet.VisualStudio.IVsPackageInstaller.

The problem seems to have something to do with the values of version, and may be packageSource.

When this error is raised the values are:

packageSource = "All" version = null 

If I change the value of version to the latest available version of the package ("3.00.00.1041") then the exception is InvalidOperationException ("Unable to find version '3.00.00.1041' of package 'Primavera.Core.Patterns.Models'.").

This does not make any sense because this works perfectly in the Package Manager Console and it installs exactly that version. It seems to be a bug in the NuGet.VisualStudio code base.

Any ideas?

1 Answer 1

2

This question has been discussed on GitHub, but the short answer is that you should use a null source instead of "All" because the "All" keyword has no special meaning in the 3.x NuGet Visual Studio extension. Using null is the recommended way of installing a package from the user's configured package sources.

Note that this can be a brittle way of installing packages since the user's configuration is typically unpredictable from the VSIX developer's point of view. A more reliable way of installing a package is by explicitly specifying the package source (and even version) when installing.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you again. In our case there is no problem in relying in the user's configuration because that is also set by the VSIX package.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.