This project is read-only.
3

Closed

Regression in 1.8: package manager cannot install or update a package if an empty folder for the target version already exists

description

BACKGROUND

It can be common to be in a situation where a package is being installed or updated and an empty folder for the target version already exists. E.g. updating a package from a local source before pushing to the gallery, reverting (which in Git and Mercurial only removes files not folders and empty folders do not show when checking status), pushing to the gallery and then updating the package from the gallery as a final test.

RECREATE

Scenario 1: A package containing a lib folder

1) Create a new project
2) In the solution directory, create an empty folder matching the path which would be used to install the latest version of a new package containing a lib folder, e.g. packages\Newtonsoft.Json.4.5.5
3) Using the package manager, install the package (make sure the version number matches the one used for the folder name). This fails with the following messages:-
'Newtonsoft.Json 4.5.5' already installed.
Successfully uninstalled 'Newtonsoft.Json 4.5.5'.
Failed to add reference to 'Newtonsoft.Json'.

Scenario 2: A package with no lib folder

1) Create a new project
2) In the solution directory, create an empty folder matching the path which would be used to install the latest version of a new package with no lib folder, e.g. packages\StyleCop.MSBuild.4.7.26.4
3) Using the package manager, install the package (make sure the version number matches the one used for the folder name). The installation appears to succeed but the folder remains empty (and install.ps1 has not been executed).

In scenario 1, at least an error message is provided so that the developer is prompted to remedy (the package folder seems to be deleted automatically but packages.config is in an invalid state and needs to be reverted). It is very obvious that the action has failed since the target library cannot be referenced in code.

In scenario 2, the failure is silent and it is not immediately obvious that the installation has failed. The package used in the example only adds build targets and it's lack of presence may only be noticed on close inspection of the build output.

WORKAROUND

Ensure that the target folder for the version of the package you are installing or updating to does not exist before performing the install or update.

NOTES

I am not sure if the regression happened between 1.6 and 1.7 or between 1.7 and 1.8. I have confirmed that the issue does not exist in 1.6 (I have an old installer for this) but I am currently unable to revert to and test 1.7 because the download link is not working.

The above recreation steps were discovered after some substantial effort in isolating the problem. I was initially alerted to the presence of an issue when updating the package https://nuget.org/packages/StyleCop.MSBuild from one version to another. I updated the package once, reverted as above, and on the second attempt to update, the single content file was being added to the project (presumably from the nupkg file in the cache) but the package folder remained empty and the Install.ps1 script failed to run. I reverted to NuGet 1.6 and performed the same steps and everything worked without any issue.
Closed Sep 19, 2012 at 1:16 AM by ClayCompton
I've confirmed that this is fixed in today's NuGet 2.1 build.

comments

adamralph wrote May 26, 2012 at 10:44 PM

I

JeffHandley wrote May 29, 2012 at 9:28 PM

Related: http://nuget.codeplex.com/workitem/2123

@pranavkm - with the fixes you're making to address issues updating packages with satellite packages in place, this could be mostly addressed (if the package folder gets deleted during uninstall).

Is there an opportunistic fix for the rest of it?

adamralph wrote May 30, 2012 at 6:32 AM

@JeffHandley - not entirely sure if I understand your comment - are you suggesting that we should rely on folder removal during uninstall to fix this? If so, I'm not convinced this is a good idea since in the above recreation scenarios there is no uninstallation step.

pranavkm wrote May 30, 2012 at 5:26 PM

@JeffHandley, since we know what satellite files are being referenced, I specifically remove satellite files clearing up the .satellite directory if it's empty. I'll have a look at what regressed.

pranavkm wrote Aug 21, 2012 at 1:08 AM

Seems like this was introduced in 1.8 with 72309a85a13af3b502347e2ea0200a6459322679 (SharedPackageRepository) and has been fixed in 2.1 via 92d4abe86375bdd964b2750fe93c9fba00d229e8.