NuGet is incredibly fragile and brittle
One of the reasons I don’t like using NuGet together with TFS is that it always manages to get confused as to where things are actually installed every time I create a new branch in TFS for projects or solutions that have NuGet packages. This is probably the most frustrating issue I have with NuGet and very little has been done on the NuGet.org side to remedy this problem automatically. I think since there is such a push from everyone to use it, and essentially it isn’t an option not to use it anymore, they should take responsibility and make it easier to fix this stupid problem every time it should occur. I really dislike the idea of having to use a shared Solution as that goes against the very idea of a Solution. Therefore binding NuGet to a common solution is an even worse idea than sharing a solution in the first place. Unfortunately that’s where we are now. Thanks for nothing?
Fixing the incredibly frustrating problem
When this problem happens, upon google searching, you will often see people state, “Just click on the Restore NuGet Packages” option at the Solution level. Yeahhhh… well this never works. I have yet to ever get this to 100% fix my problem ever. Therefore this option is pretty much worthless. Whatever you do, don’t try to fix your reference problems manually as this will usually only make things much much worse. In some cases you can get away with manual fixes for like one or two references, but if all of your references are broken then I don’t recommend it, especially for MVC projects. Instead I suggest doing the following, it is not fun, but it will eventually fix your stupid reference problems:
https://docs.nuget.org/ndocs/consume-packages/reinstalling-and-updating-packages
- Open your solution
- Open up the NuGet Package Manager Console located at “Tools > NuGet Package Manager > Package Manager Console”
- Very important – make sure to select the default project from the drop down before continuing
- Before moving on to the final step, you have to understand that this is going to more than likely affect more than just one of your projects. Therefore if your projects are in source control (which they more than likely are), prepare to check out a bunch of stuff. Just keep clicking OK until your finger hurts and falls off.
- Use the following command on each project that is having a problem:
Update-Package –reinstall
Notice that the package name is not specified, that is very much on purpose. By not specifying the package name, it will reinstall all packages for the target project.
- Chances are you are going to have to do multiple passes of this procedure… because why should it be easy? Therefore you might find it necessary after doing the initial pass to:
- Close your solution
- Close visual studio
- Re-open your solution
- Re-build your projects in whatever order you use (I only build my start up project, never the solution)
- If you still get errors then you have to start targeting projects
- Targeting a project for reinstall is the same idea as above just providing the package name as shown in the package.config – not what you see in the references of your project, they don’t always match.
Update-Package –reinstall packageNameHereFromPackageConfig
- The most valuable advice I can give you is that when you see a red error message, don’t flip out, it just means there is just one more broken NuGet reference (thanks NuGet!). Therefore pay close attention to the errors and try to re-install or plain ol’ install the package that is missing in the order required. Meaning that if you get an error for that package too, then install the package it is complaining about before trying to install the original.
- Another especially frustrating problem is that sometimes you have to install a package twice because the first time it will error, then the second time it works… because NuGet…
Nature of the beast
I am not going to explain why I think these package installs are failing or make excuses for this crap because it is just counter productive at this point. NuGet is great when it works, which in my experience is when you have a project that is not inside of source control, you are not sharing solutions and just the first time until a month later where it magically decides to stop working. I actually really dislike NuGet, but like I mentioned before, there isn’t much of a choice involved in using it because Microsoft has adopted it heavily so now there is an obligation in using it. Especially when it is baked right into the IDE. I think it is pathetic that NuGet still doesn’t work properly after this many years of existing and I feel that it is too bloated and over-complicated for its own good. Why there can’t be a simple “reinstall everything” option, I will never know until I bother trying to figure it out and I might produce a tool that will just fix all the damn problems with a single button click. I have wasted too many hours troubleshooting these stupid problems and I hate that.
Hi there!
This is fucking ridiculous… I mean TFS and NuGET what a mess.
I think would be easier just to migrate from TFS to GIT right?
GIT does not care about changing references on the packages such as TFS.
Branching sould be easier.
Thanks for your post, is very usfeul!
Totally agree. Ever since I moved to TFS Git I haven’t had a problem. Goodbye TFS VC and good riddance. I love Git.