9

I have a problem with nuget getting the first build of a specifik assembly version, not the latest build. Here are steps that explain what is going on:

  1. Removing local nuget cache.
  2. Delete project.lock.json files in project.
  3. Checking build number for latest build in nuget feed: 102
  4. Run dotnet restore --no-cache.
  5. The project folder is recreated in local cache, but with build number 98.

Both build 98 and 102 have version number 1.2. How can I force dotnet restore to take the latest build of the nuget package without increasing the version number to 1.3?

Thanks!

Jiří Kyzlink
  • 163
  • 1
  • 9
FatAlbert
  • 4,890
  • 6
  • 22
  • 34
  • Are you using floating versions (aka versions with asterisks)? Can you share your project.json or csproj file? – natemcmaster Feb 23 '17 at 14:44
  • 2
    Could be cache location that you have not cleaned: http://lastexitcode.com/projects/NuGet/FileLocations/ or nuget scratch folder: https://github.com/NuGet/Home/issues/802 – Wojtek Feb 24 '17 at 14:43

2 Answers2

16

Clear all NuGet caches with command dotnet nuget locals all --clear

Then NuGet takes the latest version of the package from the feed.

ViRuSTriNiTy
  • 5,017
  • 2
  • 32
  • 58
Jiří Kyzlink
  • 163
  • 1
  • 9
  • 1
    It will work only on developer's computer. You cant do it in build server, because it may affect other builds. – jenkas May 20 '21 at 10:04
3

Follow the answer by Jiří Kyzlink to clear your NuGet cache.

Then follow with a dotnet add ProjectName package PackageName to basically re-add the package and update the versioned reference in the project file.

dotnet restore restores references from the project file. Solely clearing the cache doesn't change your project reference.

Ropstah
  • 17,538
  • 24
  • 120
  • 194
  • 2
    Actually the cache clearing wasn't necessary. Just calling `dotnet add` again made it install the latest package. – Ropstah Jun 27 '18 at 00:55