Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nuget dependency versions

Recently in our firm we decided to upload our company developed library files into a private NuGet server. Everything seemed to be fine before version numbers started to grow. The solutions that used our NuGet libraries stopped building properly, and we believe that the versioning is the problem.

Here is the scenario:

enter image description here

This is a diagram with the references of the packages (as you can see they have references among themselves)

1) In a solution S you install from the private NuGet server for example libraries A, B, E all with version number 1.0.0.0.

2) You make a change in A and increase the version number of it to 1.0.0.1.

3) You update the library A from the NuGet Package Manager in solution S to version 1.0.0.1

4) You end up with two versions of A one for S (1.0.0.1) and one B, E (1.0.0.0)

5) In solution S, Visual Studio (Tested on 2012, 2015 Professional) shows that the reference cannot be found and wants to reinstall the package. When you do that it builds, but when you commit the next person's build fails...

Some (ugly?) work around would be not to reference the packages as NuGet, but to embed the references in the dlls. Or to go in all the packages that reference A, update it, change its version and then update S, witch sounds like awful lot of work..

And should't it just work since when you reference a NuGet package you don't specify specific version but >= version?

Or are we doing it all wrong?

Thank you!

like image 485
gyosifov Avatar asked Nov 01 '25 20:11

gyosifov


1 Answers

In your situation, there are two ways to resolve the issue when the dependent package A upgrade to version 1.0.0.1.

  1. Redirecting assembly versions at the app level. You can manually edit the app configuration file to redirect the old version of an assembly that your app uses to the new version. Then sample configuration code in app configuration file is shown as below. Detailed introduce about Redirecting Assembly Versions, please refer to: https://msdn.microsoft.com/en-us/library/7wd6ex19(v=vs.110).aspx#Anchor_2
    <dependentAssembly>
        <assemblyIdentity name="someAssembly"
          publicKeyToken="32ab4ba45e0a69a1"
          culture="en-us" />
       <bindingRedirect oldVersion="7.0.0.0" newVersion="8.0.0.0" />
    </dependentAssembly>
  1. Assign dependencies range when pack the NuGet package. Since your Package B is dependent on Package A and the Package A’s version is changed, you can assign the dependencies range for the Package A in Package B’s .nuspec file with following code. When there has higher version of Package A has installed on your solution S, the Package B will use the installed higher version. In your situation, when the Package A 1.0.0.1 installed, the Package B will dependent on the Package A 1.0.0.1.
<dependencies>
    <dependency id="Package A" version="[1.0.0.0, higher version)" />
</dependencies>
like image 103
Weiwei Avatar answered Nov 04 '25 02:11

Weiwei



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!