nuget spec dependencies, get latest version?

做~自己de王妃 提交于 2019-12-17 10:58:08

问题


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


回答1:


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




回答2:


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>



回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/24765802/nuget-spec-dependencies-get-latest-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!