سؤال

VS 2013 fails to restore a package - the package contents are not materialized - although VS/nuget appears to think that it did restore the package successfully.

If I manually uninstall and re-install the same version of that package, it works as it should.

A bare-bones repro can be downloaded as a zip. This repro has a

  • single solution with a

  • single project with a

  • single file, "packages.config", specifying a

  • single package, "breeze.edmbuilder -version 1.0.4", containing a single file, edmbuilder.cs

  • single folder, "App_Start", contains nothing but

  • the .csproj says it should have "edmbuilder.cs" which is ok because

  • it WILL have "edmbuilder.cs" when the package is restored.

When I build, VS reports that "edmbuilder.cs" is missing ... and indeed it is missing.

However, the package was downloaded; I know this because the build produces a "packages" folder that contains "Breeze.EdmBuilder.1.0.4" wherein I see that "edmbuilder.cs" is present and in the right place.

When I issue the command install-package breeze.edmbuilder -version 1.0.4, nuget reports

'Breeze.EdmBuilder 1.0.4' already installed. NugetRestoreFail already has a reference to 'Breeze.EdmBuilder 1.0.4'.

There is nothing wrong with this package AFAIK. For when I uninstall-package breeze.edmbuilder and then reinstall with install-package breeze.edmbuilder -version 1.0.4, the install works and the missing edmbuilder.cs appears in the "App_Start" folder where it belongs.

The failure is repeatable in place.

  • close the solution
  • delete edmbuilder.cs from "App_Start"
  • delete the "packages" folder
  • optionally delete the .suo and bin and obj directories
  • re-open the solution and re-build

You'll get the same failing behavior ... and the same ability to manually uninstall and reinstall.

FWIW, removing the reference to edmbuilder.cs from the .csproj has no effect.

No matter what I do, I have to manually uninstall and re-install the package.

WTF!

p.s.: I am using VS 2013 Update 2 RC. I doubt that the "RC" matters as this problem came to my attention from a customer. You never know.

p.p.s: This is not about the build failing and I don't care that this solution would never run. What you see here is a stripped down version of a real app that would have worked. The only question is "why no restored file?"

هل كانت مفيدة؟

المحلول

Package Restore is NOT the same as installing a package. What you are seeing is by design. It simply downloads any missing packages in the packages folder. No more. No less.

Package Restore was added so you wouldn't need to commit the packages folder to source control.

It is expected that you would install a package then commit the changes made to your project files as well as any files that may have been added like your edmbuilder.cs, essentially anything inside your project folder. You would exclude the packages folder.

Now when you get the source from source control everything would be present except for the package files. Package Restore would download those and now your working copy is complete.

See NuGet's Restore Package insists on specific package versions

نصائح أخرى

Is this stupid or what?

Thanks to @Kiliman for explaining that my horrible experience is "by design".

So how do you actually get the content you thought was being restored? Do you install each package one at a time. That's insane.

I was going to observe that there is no nuget equivalent of an npm install that would fetch all the packages you need ... when I discovered that there actually IS an almost-equivalent. It's just not obvious and I wonder how many people know it exists.

It's a two step process:

  1. FIRST restore the missing packages ... THEN

  2. Issue the command: Update-Package -Reinstall

This re-installs all packages in every project in your solution.

If you only want to re-install for a specific project, try:

Update-Package -ProjectName 'YourProjectName' -Reinstall

In both procedures, the -Reinstall switch strives to install the exact versions of the packages spelled out in your package.config ... and not newer "updated" packages which may or may not work for your project (but see the documentation for exceptions).

Read about update-package -reinstall in the official nuget documentation entitled, "Reinstalling Packages and its Pitfalls".

Do not miss the cautionary remarks. Clearly this technique is but an approximation of what you'd expect from other package managers.

Good luck, peoples.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top