Tomas Jansson
Tomas Jansson

Reputation: 23472

Nuget Update-Package doesn't recognize installed package --> Update failed

I have installed a NuGet package (which we have developed in the project) in a VS-project. When I run Update-Package on the nuget project i Get:

Update-Package : 'Project name' was not installed in any project. Update failed.
At line:1 char:15
+ Update-Package <<<<  Project name
    + CategoryInfo          : NotSpecified: (:) [Update-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.UpdatePackageCommand

I have checked in the package.config file to make sure the NuGet package is defined, and it is. Any clues?

Upvotes: 41

Views: 14870

Answers (6)

AaronLS
AaronLS

Reputation: 38365

My /packages/repositories.config did not have a reference to the project's packages.config named in the error. I had recently added the packages.config to this project, and the repositories.config did not checkout and was readonly, so didn't get updated to add a reference.

I manually edited repositories.config to add the path to the new packages.config.

To avoid above mentioned version conflicts I also removed all other entries in resposuitories.config temporarily. I also backedup/deleted all folders under /packages/ leaving only the repositories.config. (While VS was closed to avoid any file open/lock conflicts)

I then reopened the solution and ran the Update-Package -Reinstall command for the project, and it succeeded. I then added each other project's packages.config path back into repositories.config. I also compared each packages.config to ensure the same versions of packages were used if multiple projects referenced them.

Upvotes: 0

Thymine
Thymine

Reputation: 9195

Another way this can occur:

  1. NOT have packages being restored (Using ReSharper 2016.2 Build for example)
  2. Try to update whilst the package version in question does NOT exist in /packages/

To fix, run restore packages in some way

Upvotes: 0

Danny Tuppeny
Danny Tuppeny

Reputation: 42343

I had a very similar issue recently - turned out to be that packages/repositories.config was missing (because we don't commit the packages folder). I did something in VS (possibly adding a new package to a project) that caused VS to regenerate the repositories.config file listing all packages from all projects. After that, the update worked fine.

Upvotes: 5

Mats Mortensen
Mats Mortensen

Reputation: 506

I am working on the same project as Tomas and I have tried to figure out when this problem occurs and why. It seems this happens when we have one or more old versions of a package in the packages folder and try to issue the 'update-package' command.

Before issuing the command our packages folder and config looks like this:

Packages folder:

Common.WebApi.1.0.0.109
Common.WebApi.1.0.0.110

Packages config:

<packages>
    <package id="Common.WebApi" version="1.0.0.110" />
    <package id="System.Json" version="4.0.20126.16343" />
    <package id="System.Net.Http" version="2.0.20126.16343" />
</packages>

Now, when issuing 'update-package Common.WebApi' we get the error:
Update-Package : 'OPF.Common.WebApi' was not installed in any project. Update failed.

To fix it I delete the old package 'Common.WebApi.1.0.0.109' from the packages folder and rerun the command which then works.

The obvious question is: Why do I have an old package in my packages folder? This happens to us because we do not committ our own packages to source control. Instead, we use the approach which is described here: http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages

The 'old package problem' occurs in this situation:
1. Developer A updates a package and commits the package.config to source control
2. Developer B gets the latest version from source control and receives the updated package.config
3. Developer B builds the project and the new package is created in his packages folder
4. Nuget does not delete developer B's old package from his packages folder so Developer B now has both the old package and the new package in his packages folder, but only a reference in the package.config to the new version.

To me, it seems that Nuget does not expect there to be more than one version of a package in the packages folder and becomes confused when you to try to update a package that has multiple versions [in the packages folder] even though you only reference a single package from the package.config.

Upvotes: 49

jgauffin
jgauffin

Reputation: 101150

I had the same problem. We are not checking in the packages folder (the nuget build task downloads all packages).

The only way for me to solve the problem was to delete the packages folder and then rebuild the project.

Upvotes: 3

Saksham
Saksham

Reputation: 339

Here's how I managed to get the latest version of the package manager:

  1. Start VS2010 in admin mode (run as administrator)
  2. Tools > Add in Manager > Uninstall NuGet
  3. Restart Visual Studio
  4. Install NuGet

Voila!

Hope this helps.

Upvotes: 2

Related Questions