Local nuget package not refreshing on repackage

cw_msdn 106 Reputation points
2021-11-08T09:11:34.56+00:00

Hello forum,

My Specs:
OS: Windows 10, 64-bit, Build 19042.1288
VS: 2019 Version 16.11.3

I'm testing a local nuget package that's packaged from a C# library that I developed. I've listed the directory containing the .nupkg file as a <packageSource> in my nuget.config file. That packageSource location is listed in the VS Package Manager UI and I can access the library from the referencing project without a problem.

An issue arises however when I make changes to library and build the .nupkg fresh. I notice that these changes don't get reflected in the referencing project; I've tried to restart VS and open the solution to refresh the package reference, but with no success.

What this means to me is that the package that the referencing project uses is not the .nupkg in the <packageSource> location, though the Package Manager would imply that it is. I looked around for where the referencing project could be pulling the outdated package, and found that instead of the <packageSource>, it is referencing the old code contained in a .nupkg stored in my local user's /.nuget/packages folder. This means to get the changes to my library, I have to remove the old code in this location first.

I don't understand how / why this happens, but it seems like a simple fix for anyone that understands the background of what happens when the library gets packaged and how it ends up in my local user's .nuget/packages folder. Perhaps some setting I can change so that the old code in this /.nuget/packages folder gets overwritten upon packing the library?

Thanks in advance for any assistance you can provide!

Developer technologies | .NET | Other
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. cw_msdn 106 Reputation points
    2021-11-08T10:13:47.74+00:00

    More research led me to simply remove the package from cache by attaching a post-build command to the library. This removed it entirely from the cache then, and upon any changes to the library, reference projects have to find the updated version of the library rather than use the cached version!

    "RD /S /Q "/localuser/.nuget/packages/<cached library folder"

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. cw_msdn 106 Reputation points
    2021-11-08T09:30:28.703+00:00

    So looking a bit more into this, I found this MS article about the local nuget cache: https://learn.microsoft.com/en-us/nuget/consume-packages/managing-the-global-packages-and-cache-folders.

    The referencing project will reference the cache first, which is essentially this .nuget/packages as I understand it. One can clear the cache manually, but is this the only way? Is there a way to automatically clear the cache upon building the .nupkg?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.