Nuget V3 Http Cache Path Length Issues
The issue Today, I got hit with a strange issue when trying to restore a NuGet package in a project. I had just updated a package version to a new prerelease version (with, granted, a pretty long name along the lines of MyCompany.MyDepartment.MyPackage.Something.OpenTelemetry.Common.1.5.0-FEATURE-BRANCH-NAME_TICKET-NAME-12345.BUILD_NUMBER) and was trying to restore when - well, nothing happened. The Visual Studio Package Manager output just said: Could not find part of the path 'C:\Users\vinkemeier\AppData\Local\NuGet\v3-cache\7c65f951c65b434c5601ab3dd905646debe8d198$_api_nuget_v3_nuget-feed-name\list_mycompany.mydepartment.mypackage.something.common_range_1.2.0-FEATURE-BRANCH-NAME_TICKET-NAME-12345.BUILD_NUMBER-1.3.0FEATURE-BRANCH-NAME_TICKET-NAME-12345.BUILD_NUMBER.dat-new' I was first thinking that the issue might be in package availability in the custom NuGet feed, but I could access the package via the browser UI. I also tried to clear the NuGet cache with dotnet nuget locals all --clear, but that didn’t help either. After some time, it occurred to me that the path length of the cache file might be the issue. And, of course, when googling for path length issues, you quickly find a GitHub issue from 2019 in the NuGet repository that describes this behaviour. The workaround Sadly, although being closed, the issue is still present in the current Visual Studio 2022 preview. However, a “workaround” is available: Change the NuGet HTTP cache path to a shorter one. So, I changed the NUGET_HTTP_CACHE_PATH environment variable to a shorter path (e.g. C:\NuGetCache), restarted Visual Studio and it worked normally again. Let’s hope this works long enough and our paths don’t keep getting longer. If I have that issue again on a new machine, I at least now have this documented for my future self :)