I'm trying to synchronize all of the DLL versions in my solution with many projects. I noted that my app.config contains several assembly binding redirects like so:
<dependentAssembly>
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.1" newVersion="4.0.2.1" />
</dependentAssembly>
However, as best I can tell via the NuGet package manager, there are no packages that need consolidation and all projects point to version 4.4.1 of that assembly
I tried folowing the advice of this blog post. I deleted all of the binding redirects and attempted to regenerate via:
Get-Project -All | Add-BindingRedirect
According to the NuGet Documentation Add-BindingRedirect
should check the projects output path. I am assuming this means the bin folder.
But after cleaning and rebuilding Get-Project -All | Add-BindingRedirect
still produces the same redirects in my app.config
.
Where does the NuGet Get-Project -All | Add-BindingRedirect
get its version numbers?
And where might these incorrect NuGet Package Versions be coming from?
Open the NuGet Package Manager Console, specify the appropriate Default Project and enter the command Add-BindingRedirect. As if by magic, an app. config is added to the project (if one doesn't exist already) and the appropriate information added.
Yes, the Add-BindingRedirect
adds <assemblyBinding>
tags to the configuration file even after clearing all files in the output folder (seems like the documentation is not accurate in this regard !!).
Apparently Add-BindingRedirect
scans all of the referenced DLLs and all of their dependencies, and if it finds any conflicts throughout the dependency tree it generates the required assemblyBinding
s.
If you have a csproj called "MyProject" which references two DLLs (from two different Nuget Packages)
SomePackage.dll
AnotherPackage.dll
And both DLLs reference BasePackage.dll
, but each one of them references a different version of the BasePackage.dll
, for example:
SomePackage.dll
references BasePackage.dll
version 1.AnotherPackage.dll
reference BasePackage.dll
version 2.When you run Add-BindingRedirect
command, it will scan all the DLLs referenced by "MyProject" and spot this conflict in BasePackage
references, then adds something like this to your configuration file.
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="BasePackage" publicKeyToken="50bd4fe62226aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With