31

In the nuspec versioning docs I see

1.0  = 1.0 ≤ x
(,1.0]  = x ≤ 1.0
(,1.0)  = x < 1.0
[1.0] = x == 1.0
(1.0) = invalid
(1.0,) = 1.0 < x
(1.0,2.0) = 1.0 < x < 2.0
[1.0,2.0] = 1.0 ≤ x ≤ 2.0
empty = latest version.

I have a packages.config that looks like this

<packages>
  <package id="psake" version="4.2.0.1" />
</packages>

and I would like to change the version to "latest".

I've tried both

<packages>
  <package id="psake" version="" />
</packages>

and

<packages>
  <package id="psake" />
</packages>

but both result in Unable to parse version value '' from 'packages.config'.

I am using Nuget.exe 2.8.2

George Mauer
  • 117,483
  • 131
  • 382
  • 612

4 Answers4

42

As of Nuget 2.8 you can add the following attribute to your nuget.config

<configuration>
    <config> 
        <add key="dependencyversion" value="Highest" /> 
    </config>
</configuration>

When resolving your packages, the latest version of that package will be resolved. Other attributes include HighestMinor, HighestPatch and lowest (based on semantic versioning)

Source: http://docs.nuget.org/docs/release-notes/nuget-2.8

Joseph Devlin
  • 1,754
  • 1
  • 26
  • 37
  • where does this entry go? my nuget.config has the following: – learnerplates Apr 30 '15 at 11:09
  • 1
    @learnerplates I have updated the answer to provide you some context. Basically you just add that section below the configuration. If you have any more questions feel free to ask – Joseph Devlin Apr 30 '15 at 11:26
  • Adding this, does not change anything for us. NuGet just takes the same hard coded version as always. What can we miss here? – tomwaitforitmy Mar 15 '21 at 12:42
5

I am guessing you are trying to use nuget install or nuget restore to pull down the NuGet package using NuGet.exe.

The version attribute in the packages.config defines the version installed in the project or solution.

To get the latest version of the psake NuGet package you would need to install it using the Package Manager console, or the Manage Packages dialog or by knowing the exact version of the package, adding that into the packages.config file, and using package restore. Since psake is a solution level package it does not update your project the last option is feasible.

The version ranges are used to restrict the package versions that are allowed to be installed in your project.

<packages>
    <package id="SomePackage" version="2.1.0" allowedVersions="[2,3)" />
</packages>
Matt Ward
  • 47,057
  • 5
  • 93
  • 94
  • Yes, this is all at the solution level, this has nothing to do with package restore, it's a script run directly from my CI that basically sets up the environment for my build tools in the next build step. I'm basically doing `./.nuget\NuGet.exe install ./.nuget\packages.config`. The question is really what does the spec mean by `empty = latest version.`? I tried both variations of "empty" that I could think of and got parse errors from both. – George Mauer Jul 15 '14 at 20:55
  • `empty = latest version` - this refers to a version range. It is used in the package/@allowedVersions or dependency/@version. Empty here is equivalent to not having the attribute. So it would mean allow the package to be updated to any later version, or the dependency can be any version. package/@version does not support a version range. To get the behaviour you want I suspect you will need to write your own utility. – Matt Ward Jul 16 '14 at 09:56
  • What I want is to allow the package to be updated to any later version like you say. However when I leave off the attribute entirely I still get that parse error – George Mauer Jul 16 '14 at 15:31
  • [`allowedVersions` syntax with examples here](https://learn.microsoft.com/en-us/nuget/concepts/package-versioning#floating-version-resolutions), I believe. – ruffin Jul 28 '21 at 17:37
0

Alternatively, you could run restore on an arbitrary version followed by update as per https://docs.nuget.org/consume/command-line-reference. To ensure the latest you would need to re-run update.

Update packages to latest available versions. This command also updates NuGet.exe itself. Please note that the presence of Packages folder is required to run the Update command. A recommended way is to run NuGet.exe Restore command first before running the Update command.

KCD
  • 9,873
  • 5
  • 66
  • 75
  • Sorry, but this doesn't really answer what I was asking. This isn't about how to "update" to the latest, but how to "specify" latest, was that not clear in the question? – George Mauer Jul 08 '15 at 14:58
  • I forgot to say in the answer this is just an alternative, not exactly what you were after but it may suit other people. The outcome is the same is it not? – KCD Jul 09 '15 at 01:37
  • It really isn't though, the specification is instructions for the package manager on *what to do when updating*. Actually running the update command is quite different. – George Mauer Jul 10 '15 at 18:22
-1

You can modify your .cspoj file to execute a "BeforeBuild" target like this :

<Target Name="BeforeBuild"> <Exec Command="&quot;$(SolutionDir).nuget\NuGet&quot; update &quot;$(ProjectDir)packages.config&quot; -Id psake" /> </Target>

Note that : u'll need to have the "Nuget.exe" in ur solution directory.