Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating Nuget Package of the Same Version Number

I'm developing a .net Standard C# class library which automatically outputs a NuGet package whenever I build it. I am consuming this NuGet package with an ASP.NET Core application. If I update the version number of the class library each time I build it, I can pull in the changes into my application using a simple Update-Package command, but I don't want to have to change the version number each time, when I'm making lots of small changes.

I've tried clearing the NuGet cache in the Visual Studio Options menu and then tried using "dotnet restore" and also Uninstall / ReInstall, but somehow it still seems to keep pulling in an older version from somewhere.

Is there any other way of doing this? Where would it be pulling the older version from?

like image 944
fosbie Avatar asked Aug 15 '19 10:08

fosbie


2 Answers

That's simply not how NuGet works. Version numbers are idempotent, so you cannot "replace" a version; you can only increment it. This is a rule of SemVer (semantic versioning), which NuGet follows. The rule states:

Once a versioned package has been released, the contents of that version MUST NOT be modified. Any modifications MUST be released as a new version. (https://semver.org/#spec-item-3)

There's two things that can help you, though.

  1. NuGet employs SemVer, so you should as well. In development, you do not increment the major, minor or patch numbers ([major].[minor].[patch]). Instead, you add a dash, followed by a prerelease identifier, i.e. 1.0.0-alpha.1. This then allows you to increment the identifier without affecting your release numbers. For example, your next change might be 1.0.0-alpha.2, and when you're finally ready for release, you only then use just 1.0.0.

  2. In development, you shouldn't be modifying your NuGet in conjunction with your app code. If they're in the same solution, a package reference is unnecessary, as a project reference makes more sense, and with that, no version increment is necessary. You should only be including via package reference if the library is in a different solution than your app, and then, you should be developing the two independently. You can also separate the projects later, if that makes more sense. If your library isn't developed enough to be able to support your app without constant changes, then keep it in the same solution. Once it reaches a stable point, you can then move it out to its own solution if that's what you prefer, and change the reference in your app at that point.

like image 167
Chris Pratt Avatar answered Sep 22 '22 07:09

Chris Pratt


You can apply this version to your pre-release package to get a package per build :

<Version>1.0.0-$(Configuration)-$(Platform)-$([System.DateTime]::UtcNow.ToString(yyyyMMdd-HHmmss))</Version>

Then when you release your package, you change the version with :

<Version>1.0.0</Version>

You always have to do the upgrade of package but it's version is not incremented

like image 34
Troopers Avatar answered Sep 25 '22 07:09

Troopers