Nuget Packages. Personal experience updating packages

image

Good day, the inhabitants of Habr. Today I would like to discuss with you the topic of updating packages through Nuget Packet Manager and talk about ways to do this correctly. I propose to consider the situations that I happened to encounter, and the solutions for them that occurred to me / my colleagues. I will be happy to hear your solutions to these problems / new problems that you have encountered!


Upgrading to a specific version of some packages

In our case, we needed to update the group of packages to a specific version, we will call them conditionally: UPacket1, UPacket2, UPacket3, which needed to be updated from version 1 to version 2, for clarity. The problem appeared when it was discovered that for each of them there are still many other packages in Dependence *, it is important to note that for each of the packages in Dependence there is a condition "> = version" (if you have a strict condition, then this problem should not arise). If you simply write the Update-Package UPacket1 command, then all the packages from its list of dependencies will be automatically updated to the maximum available version - but we did not need it. Why? For example, UPacket1 has a dependency on Microsoft.AspNet.Mvc, which as a result will be updated to version 5, although the whole project was originally designed for Mvc 4. We solved the issue by banal adding the allowedVersions = attribute for the necessary packages (in packages.config) "[current_version]", example:


The solution itself was easy and we did a little blood (although we had to tinker with some packages, because they had to be updated to a certain version but not the maximum, to not do it manually, we could also apply this attribute), but the search for this solution itself took which that time.
It should also be noted that the versions in this attribute can be specified as a comma / dash, with different brackets. More information about the versions and this attribute can be found here .
There was an idea to write such a program that would help automate this process, but so far the hands have not reached.

Conflicts in content files when updating packages

Often a situation arises when you modify the files provided in packages. In this case, further attempts to update such a package may cause file conflicts. Usually there is nothing wrong with this, we just skip the conflict file (skip * ) and then just look for this file in the packages folder and update the necessary file in the project manually (comparing them, what has changed, what needs to be added / deleted in the project file) . For the comparison and join process (merge *) of files I use a very convenient program - Araxis. But what if your project has about 100 packages and a dozen conflicts in many of them (in our project there are about 10 topics, each of which provides a lot of files). Araxis can also compare entire folders, which is why I decided to write a program that will collect from all packages (from their “Content” subfolders) all files in one place. Then I simply compare these files with the project files as a whole, it is much faster than manually entering each package and comparing its contents with the project. If you are too lazy to write such a program and there will be several such people, I will post it in a separate topic with a description.

So far, this is all from interesting things that could be shared on this topic. As something new arises, I will update or add new parts. And what kind of problems did you encounter? How did you decide? Write in the comments, it will be possible to discuss, and the most interesting to put out in the article.

Also popular now: