Nuget更新 [英] Nuget update on build

查看:61
本文介绍了Nuget更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难让我的项目在重建时更新我们的内部nuget程序包.每次构建依赖于它的项目时,我们都需要有几个核心参考库是最新的.

I'm having difficulties getting my project to update our in-house nuget packages on a rebuild. We have several core reference libraries that we need to be current every time a project that depends on it is built.

我正在使用Visual Studio 2017和nuget 4.7.1

I'm using visual studio 2017 and nuget 4.7.1

我已经将有问题的项目转换为使用包引用方法而不是package.config,但是它在项目文件中生成的详细信息与教程中所说的有所不同.

I've converted the project in question to use the package reference method instead of package.config but the details it's generating in the project file are different to what the tutorials say.

这是我在项目文件中得到的:

Here's what I've got in my project file:

<PackageReference Include="SMSCore">
  <Version>10.5.0</Version>
</PackageReference>
<PackageReference Include="STMICore">
  <Version>10.5.0</Version>
</PackageReference>

虽然nuget文档说了这一点:

The nuget documentation says this though:

<!-- Accepts any 6.x.y version. -->
<PackageReference Include="ExamplePackage" Version="6.*" />
<PackageReference Include="ExamplePackage" Version="[6,7)" />

https://docs.microsoft.com/zh-CN/nuget/reference/package-versioning

我尝试更改项目文件以使其看起来像参考资料.
我已经尝试过以项目文件开始使用的格式使用版本控制方法.

I've tried altering my project file to look like the reference material.
I've tried just using the versioning methods in the format the project file started in.

似乎什么都没用.
也许我看错了文档?
我对定义和使用nuget存储库还很陌生,因此如果它很简单,我就不会感到惊讶.

Nothing really seems to be working.
Maybe I'm looking at the wrong documentation?
I'm pretty new to defining and using nuget repositories so I wouldn't be surprised if it's something simple.

任何帮助将不胜感激.谢谢.

Any help would be greatly appreciated. Thank you.

推荐答案

我想我想知道的是,在构建项目时是否有可能让项目更新其所有相关的nuget包?

I guess what I need to know is if it's possible to have the project update all its dependent nuget packages when the project is built?

如果您使用的是 package.config ,则更新其所有相关的nuget软件包将非常容易.我们只需要添加一个预构建事件即可对其进行更新:

If you are using the package.config, it will be very easy to update all its dependent nuget packages. We just need add a pre-build event to update it:

<YourNuGetCLIPath>\nuget.exe update "YourSolutionFile.sln or PackageId"

检查更新命令(NuGet CLI)有关更多详细信息.

Check update command (NuGet CLI) for some more details.

如果您使用的是 PackageReference ,它将变得更加复杂.那是因为 NuGet.exe 更新不支持 PackageReference .在这种情况下,我们必须使用浮动版本来自动更新软件包(您在问题中提到),但是它不适用于所有依赖的nuget软件包,因此浮动版本似乎也不适合您.更重要的是,如果您使用的是 PackageReference ,则NuGet软件包管理UI上还有另一个问题:

If you are using PackageReference, it will become a bit more complicated. That because NuGet.exe update does not support PackageReference. In this case, we have to use floating versions to automatically update packages (You mentioned in the question), but it not work for all its dependent nuget packages, so floating versions does not seem to suit you either. what's more, if you are using PackageReference, there is another issue on the NuGet Package Manage UI:

此外,如果您的项目类型是SDK < Project Sdk ="Microsoft.NET.Sdk"> ,则还有另一种解决方法,可以使用 PackageReference ,则可以在构建前事件中使用 dotnet add 更改 PackageReference 的版本:

Besides, if your project type is SDK <Project Sdk="Microsoft.NET.Sdk">, there is another workaround to update all its dependent nuget packages with PackageReference, you can use dotnet add to change the version of the PackageReference in the pre-build event:

dotnet add "$(ProjectPath)" package PackageID

如果您使用的是 non-SDK + PackageReference ,我还没有找到任何有效的解决方法.

If you are using non-SDK + PackageReference, I have not found any valid workarounds yet.

因此,如果没有使用 package.config 的限制,我认为 package.config 最适合您.

So, if there is no restriction on using package.config, I think package.config is best for you.

希望这会有所帮助.

这篇关于Nuget更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆