Brandon O'Dell
Brandon O'Dell

Reputation: 1171

NuGet auto update specific package

I am attempting to configure my project / nuget to auto update a specific nuget package. I am currently using NuGet Version 2.8.* and an using the Automatic Package Restore in Visual Studio strategy. My question is what is the best approach to get NuGet to auto update a project before my app builds? Is what I am trying to do even possible using the Automatic Package Restore strategy? Or do I need to use Command-Line Package Restore wrapped in MSBuild, and specify custom update command and target in the NuGet.targets file?

Upvotes: 0

Views: 2266

Answers (2)

P Motameni
P Motameni

Reputation: 31

This is an old post but in case someone lands here. One option could be using pre-build script to run below command:

nuget update configPath  packageid

Config path could be either project ".cproj" path, solution (.sln) path, or the package.config file path.

https://learn.microsoft.com/en-us/nuget/tools/cli-ref-update

Note that it seems nuget CLI does not work for .NET Core. For Core you need to use dotnet CLI which has integrated nuget command. But that does not have a separate update command (at the time of this post). You need to use add to update but that command needs an explicit version number. So a workaround could be calling remove and then add commands.

Upvotes: 1

natemcmaster
natemcmaster

Reputation: 26773

Not currently possible with Visual Studio tooling. NuGet will not automatically upgrade your package version. You must still do this manually.

Not recommended, but in theory, you could write your own script to query nuget.org for the latest version and then upgrade the version number in packages.config. But this seems like a dangerous approach.

Upvotes: 3

Related Questions