📜 ⬆️ ⬇️

Nuget Packages. Personal experience of updating packages

image

Good day, residents of Habra. Today I would like to discuss with you the topic of package updates through Nuget Packet Manager and talk about ways to do it right. I propose to consider the situations that I have had to face, and solutions for them that came to my / my colleagues. I am pleased to hear your solutions to these problems / new problems that you have come across!


Upgrade to a specific version of some pekedgei

In our case, we needed to update the group of packages to a certain version, let's call them conditionally: UPacket1, UPacket2, UPacket3, which needed to be updated from version 1 to version 2, for clarity. The problem arose when it was discovered that for each of them there are still many other packages in the dependency * , it is important to note that for each of the packages in the dependency there is a condition “> = version” (if you have a strict condition, then there is no such problem must). If you just write the Update-Package UPacket1 command, then all packages from its dependency list will be updated to the maximum available version automatically - and we did not need it. Why? For example, UPacket1 has a dependency on Microsoft.AspNet.Mvc, which as a result will be upgraded to version 5, although the entire project was originally designed for Mvc 4. We solved the question by adding the requiredVersions = attribute for the right packages (in packages.config) "[current_version]", example:
')
<package id="Microsoft.AspNet.Mvc" version="4.0.30506.0" targetFramework="net45" allowedVersions="[4.0.30506.0]" /> 

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

Conflicts in content files when updating packages

Often there is a situation when you modify the files provided in the packages. In this case, further attempts to update this package may cause file conflicts. Usually there is nothing wrong with that, we just skip the conflict file (skip * ) and then simply look for this file in the package folder and update the necessary file in the project manually (comparing them, what has changed, what needs to be added / removed in the project file) . For the process of comparing and joining (merge * ) files, I use a very convenient program - Araxis. But what about if there are about 100 packages in your project and ten conflicts in many of them (there are about 10 topics in our project, each of which provides a lot of files). Araxis is also able to compare folders as a whole, for this reason I decided to write a program that will collect all the files from their “Content” subfolders into 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 content with the project. If you are too lazy to write such a program and there are several such people, I’ll post it with a separate topic with a description.

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

Source: https://habr.com/ru/post/207554/


All Articles