问题
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.
I'm using visual studio 2017 and nuget 4.7.1
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>
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/en-us/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.
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.
回答1:
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?
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"
Check update command (NuGet CLI) for some more details.
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:
NuGet Build Integrated Project handling of floating versions and ranges in Visual Studio Client
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
If you are using non-SDK
+ PackageReference
, I have not found any valid workarounds yet.
So, if there is no restriction on using package.config
, I think package.config
is best for you.
Hope this helps.
来源:https://stackoverflow.com/questions/52250057/nuget-update-on-build