Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make NuGet pack not overwrite an existing version

Tags:

nuget

When building a NuGet Pack to an output directory, I do not want it to overwrite an existing version

Existing command:

".nuget\nuget.exe" pack "some.csproj" -output "c:\~packages"

I have looked through the documentation and cannot seem to find a switch that does it. I tried using a if exists "c:\~packages\some.nupkg" exit 1 but the problem is I do not have access to the version number in that context, so I cannot predictably provide a version to check for

like image 464
Gent Avatar asked Oct 27 '25 20:10

Gent


1 Answers

This is not currently possible using NuGet.exe.

The options are:

  1. Modify NuGet's source code to allow an extra command line option to support not overwriting the existing NuGet package if it exist. The PackCommand could be changed to support this.
  2. Write a utility to generate the correct package version, then check the package exists before running NuGet.exe. The package version information is read from the AssemblyInformationalVersionAttribute taken from the project's output assembly if you are using nuget pack projectfile.
like image 74
Matt Ward Avatar answered Oct 31 '25 00:10

Matt Ward



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!