Question

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...
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top