How to force Nuget not to update log4net to 1.2.11

That’s a quick one. There’s been a new release of log4net recently that’s signed with a new key, and there­fore is incom­pat­i­ble with old ver­sion 1.2.10.

There­fore, due to near-ubiquity of the library in .NET space, it may cause some prob­lems if you hap­pen to have a depen­dency (direct or indi­rect) on it.

The mat­ters are made worse by Nuget’s default of get­ting the lat­est avail­able ver­sion of the pack­age. I dealt with this prob­lem the other day, and I saw a few peo­ple in my twit­ter stream strug­gling with the same issue.

The solu­tion is quite sim­ple. It’s not spe­cific to log4net and I’m not pick­ing on log4net here. Here’s how you can restrict Nuget’s pack­age to spe­cific ver­sion in your solution.

 

So imag­ine you install a pack­age that has a depen­dency on log4net. In this case, the depen­dency is spec­i­fied as specif­i­cally ver­sion 1.2.10 (as opposed to Nuget’s default: this ver­sion of newer).

nuget_core

If after that we install another pack­age that also depends on log4net but doesn’t restrict the ver­sion, we’ll have a problem.

nuget_log4net_fail

The pack­age we were try­ing to install doesn’t get installed. Actu­ally, even if it did, we would have a prob­lem since it most likely was com­piled against log4net 1.2.10 any­way, and if Nuget updated log4net to ver­sion 1.2.11 the app would throw an excep­tion at run­time due to mis­matched assembly.

So there is a solu­tion to restrict ver­sion of the pack­age to spe­cific ver­sion (in this case 1.2.10) as spec­i­fied in the documentation.

nuget_log4net_fail_solution

After adding allowedVersions=”[1.2.10]” we can try again and this time the pack­age will install properly.

nuget_log4net_fail_avoided

Notice it says it installed log4net 1.2.11. I checked my pack­ages folder, and project depen­den­cies and the ver­sion ref­er­enced was 1.2.10 so all is good.

Hope that helps