Search code examples
nuget

How to make NuGet pack not overwrite an existing version


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


Solution

  • 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.