自动选择最新版本的私有程序包参考Nuget

时间:2019-03-02 10:04:57

标签: .net-core nuget packagereference

我知道之前已经有人问过这个问题,但是没有任何答案,或者nuget听不到我的packagereference。

我有一个私人的nuget仓库,有2个程序集:

<PackageReference Include="ProjectX.Core" Version="1.0.0.20" />
<PackageReference Include="ProjectX.Domain" Version="1.0.0.20" />

根据official docs,我想要的是nuget可以在还原时自动获得最新版本(通过azure devops),我应该这样做:

<PackageReference Include="ProjectX.Core" Version="1.*" />
<PackageReference Include="ProjectX.Domain" Version="1.*" />

但是当我查看它时,它会尝试还原到1.0.0版(甚至不可用)。

如何使nuget自动获取最新版本?

1 个答案:

答案 0 :(得分:0)

“为我工作”。如果不适合您,如果您可以提供Minimal, Complete, and Verifiable example,我们也许可以调试并查看问题所在。

复制步骤:

# setup isolated nuget environment
dotnet new nugetconfig
# you need to download nuget.exe for these commands, otherwise you have to hand edit nuget.config
nuget config -configfile .\nuget.config -set globalPackagesFolder=gpf
nuget sources -configfile .\nuget.config remove -name nuget
nuget sources -configfile .\nuget.config add -name local -source source

# create nupkgs
dotnet new classlib -n MyLib
cd MyLib
dotnet msbuild -t:pack -p:packageoutputpath=..\source -p:version=1.0.0.1
dotnet msbuild -t:pack -p:packageoutputpath=..\source -p:version=1.0.0.2
dotnet msbuild -t:pack -p:packageoutputpath=..\source -p:version=1.0.0.10
cd ..

# use latest version
dotnet new console -n MyApp
cd MyApp
dotnet add package MyLib --version "1.*"

# check version used. I'm using Powershell
Select-String -Path .\obj\project.assets.json -Pattern MyLib/
相关问题