1

Let's say I have a windows forms application with a few Nuget packages that are important and need to be kept up-to date.

Is it somehow possible to update Nuget packages programatically from a non-development environment? With a non-development environment I mean a random user that is running the WinForms application (having it installed on their pc).

I've read some things about using nuget.exe, but updating the nuget packages should result in .dll files to be placed in the installation folder.

thatguy
  • 21,059
  • 6
  • 30
  • 40
stefan
  • 165
  • 1
  • 15

2 Answers2

3

You can do that, but you should not do it. NuGet packages are development dependecies and not meant to be updated arbitrarily in an already compiled application or at the customer site, because

  • You cannot be sure that your application will work with the updated assemblies, since they may introduce changes that will lead to crashes or unexpected behavior at runtime.
  • NuGet packages not only include assemblies, but also build scripts and resources that may depend on MS Build or other tools that run in your development environment to be deployed or even included in your own assembly, like embedded resources.
  • Packages have dependecies to assemblies and other packages. You will need to update the dependencies, too, and there is a lot of potential to break anything with it.
  • You would need to include the NuGet CLI executable when shipping your application and your customer would need to a allow for pulling and installing packages.
  • Installing packages without testing them first may harm the quality of your application and could also introduce security issues. Remember that you may be dealing with executables from a potentially public package source.

That being said, do not do it. Instead, follow a responsible software develpment cycle, where you update packages and test your application throughly before delivery and provide frequent updates of you whole application to your customers.

Nevertheless, for educational purposes, you can install packages locally with Nuget CLI tools, in this example nuget.exe. You need to specify the package identifier, the output directory and the framework, like net472 for .NET Franmework 4.7.2. This will extract the contents, as well as the package itself to the output folder in the package folder structure that will not match your target directory structure. From there, you would need to copy the assets that you need into your install directory e.g. with a copy script. Apart from not being the right thing to do, this is very cumbersome and most likely deemed to fail.

nuget install <PackageId> -OutputDirectory <OutputDirectory> -Framework <Framework>
thatguy
  • 21,059
  • 6
  • 30
  • 40
  • Thank you for the information :) I was a bit skeptical at first but it seemed too good to be true after all. – stefan Jul 06 '20 at 13:31
  • I realize this doesn't necessarily make it smart, but aren't your concerns what [semantic versioning](https://semver.org/) is intended to address? I mean, you **should** want the latest security patches for your dependencies, and I'd want to stay on the release train at least through `VersionInUse.*.*`. I'm not saying it's necessarily easy, but [npm has gotten extremely nuanced](https://stackoverflow.com/a/25861938/1028230) in its approach to automatic updates, & [nuget supports much of the same](https://docs.microsoft.com/en-us/nuget/concepts/package-versioning#floating-version-resolutions). – ruffin Aug 12 '21 at 13:52
0

If it is auto-update, just think about if some method is supported in old version of dll, and in the new version it has been removed. 

Though you can update the package suring build time.

Enable automatic package restore by choosing Tools > Options > NuGet Package Manager, and then selecting Automatically check for missing packages during build in Visual Studio under Package Restore.

Reference: https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore#restore-packages-automatically-using-visual-studio

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197