Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I re-package NuGet packages once they're declared as ready for Production?

I have a solution which produces several NuGet packages, and I pack the packages during build. I want my nightly builds to be marked as pre-release, so I version my packages accordingly: 1.2.3-PreRelease0001. However, once a nightly build passed testing, I want to publish the same build, with the same packages, but using a non-PreRelease version: 1.2.3.

My question: How can I re-package a NuGet package with a different version? I guess I could hack some unzip/edit/nuget pack script, but is there a better way?

Alternatives:

  • Don't package during build - package in a separate process, which I can re-run later.
    Con: If I package during build, I get access to <Content> files directly from the sources
  • Run another build, this time packaging with the non-PreRelease version.
    Con: Want to distribute the exact same bits I tested...
  • Don't mark nightly builds as PreRelease, and instead publish them to a separate repository.
    Con: PreRelease packages are not marked as such, and could get mistaken as released.
  • Package during build twice: Once with PreRelease and once without.
    Con: People might be tempted to ref the non-PreRelease versions. Maybe I could put them inside some GeneratedDoNotTouch folder...
like image 396
Jonathan Avatar asked Nov 10 '22 09:11

Jonathan


1 Answers

There is no public API to change a package’s metadata in NuGet. I would say the last solution, i.e., produce both the prerelease and non-prerelease packages during build, is the best.

To prevent people from accidentally using the non-prerelease package, you can create it in a private directory first. Then, publish it only after the build passes testing.

Yes, you can extract the nuspec file from the package, make the necessary changes and then save the file back into the package. The problem is that this might stop working if the nuspec format is changed.

like image 109
Fei Ling Avatar answered Dec 25 '22 20:12

Fei Ling