.Net Nuget and the annoyingly cached Dll



A perennial problem as a developer is remembering how to fix that weird bug that last happened two years ago, only on a tuesday and only if it was raining for some reason. You spent 4 hours googling some arcane corners of the internet, stumbling across many a red herring before finding that golden stack overflow article. Now you're sat there wishing you commented your code or saved the link.


A not quite so dramatic bug caught me out a while ago when working on the Harrogate Theatre site and caught me out just last week while writing some .NET for a new client. I'm writing how to fix it here for the next time it happens and in case it happens to you!


Both sites were Umbraco (I love umbraco), so I was writing them in C# using visual studio. As anyone who writes .NET code often will know .dll versioning can be a bit tricky if it goes wrong, there are some common errors that can be fixes easily enough by downloading a new version or adding in some web config settings.


This bug started out as one of those, but turned out to be a bit more annoying. We structure our umbraco sites in two projects within visual studio, one with the umbraco site (web project), one with controllers, models and all the extension code for our sites (core). This means we need to install the umbraco dll's in both projects with the correct versions.


I was getting a version mismatch error on my umbraco dll after an upgrade to one of the projects as I forgot to upgrade the core version along with the web one. No problem, I upgraded the core project version also and recompiled. No joy, I was still getting the version error, I did all the usual things; delete the dlls from the bin folders, check my webconfig for the right version, make sure the packages were the same version...but it still wasn't working.


I even went and deleted the cached nuget packages from the c:/users/user/AppData/local folder, still no joy. Everything looked right but every time I built, the wrong dll was being put into the bin folder of my project. Even now I can't find the root cause of this but it turns out when you download a nuget package for a project, it gets added to the packages folder for the solution but the old version isn't deleted even if it's not used, it seems that sometimes visual studio doesn't get the message that the version has been upgraded, even if everything reports that it has no copies of the old version on build. Delete the old version folder from the packages folder and rebuild, boom it's working again!


Get in touch


See how we can improve your online presence.


Start your next project