Nuget Update-Package incorrectly updates assembly binding redirects

I have an internal NuGet package containing one dll, no external dependencies of the NuGet package and web.config conversions.

However, when I run the Update-Package for my projects (lib class and website) for that particular NuGet, it automatically updates my website. binding bindings of the web.config assembly to versions older than System.Web.Mvc and Newtonsoft.Json. The web.config website is currently tied to the latest version used.

Using the GUI, using the NuGet package management packages to solve ... I am choosing to UPDATE this NuGet for applicable projects that reference the old version. Then select Update

Here is the result from the package manager: http://pastebin.com/3ySwTRFR

And my web.config switched from:

<dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> </dependentAssembly> 

To:

  <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="0.0.0.0-4.0.0.1" newVersion="4.0.0.1" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" /> </dependentAssembly> 

In the NuGet package that I am updating, there is a dll that references Newtonsoft.Json (but does not explicitly make the NuGet package dependent)

When an unknowing developer updates this NuGet package, he interrupts the working environment by looking for an old version of the MVC DLL or JSON.NET.

In the past, I tried to use - IgnoreDependencies powershell command switch , but this does not seem to affect the problem.

Any idea on what can transform my web.configs (without explicit conversion) in a service pack?

Edit: VS2015 w / NuGet 3.3.0 seems to behave better ... during a random package update, he discovered that the old BAD binding redirects and fixes it! enter image description here

+7
visual-studio-2013 asp.net-mvc nuget assembly-binding-redirect
source share
2 answers

NuGet 3.3.0 does not have the option to redirect binding forwarding: Issue No. 1147

enter image description here

+7
source share

I have a better solution. Because I'm completely crazy when I have to update more than 72 links every time I update my packages, I developed a PowerShell script that updates your Web.Config based on the packages in your packages.config file and the DLL that you published to the directory Bin

 param ( [Parameter(Mandatory=$false)] [string] $webConfigPath, [string] $packagesConfigPath, [string] $binPath ) [bool]$isWindowsFormsAssemblyLoaded = $false [System.Xml.Linq.XNamespace]$ns1 = "urn:schemas-microsoft-com:asm.v1" function ClearBindings([System.Xml.Linq.XDocument] $xml) { $elements = $xml.Root.Element("runtime").Element($ns1 + "assemblyBinding").Elements() $l1 = New-Object "System.Collections.Generic.List[System.Xml.Linq.XElement]" $l1.AddRange($elements) $l1 | ForEach-Object { $_.Remove() } } function GetPackageList([System.Xml.Linq.XDocument] $xml, [string] $binPath) { $elements = $xml.Root.Elements("package") $l1 = New-Object "System.Collections.Generic.List[System.Xml.Linq.XElement]" $l1.AddRange($elements) [System.Collections.Generic.List[string]]$packageList = New-Object "System.Collections.Generic.List[string]" $l1 | ForEach-Object { $packageList.Add("$binPath\" + $_.Attribute("id").Value + ".dll") } return $packageList } function ExtractPublicKey([System.Reflection.Assembly]$asm) { $bytes = $asm.GetName().GetPublicKeyToken() return [System.BitConverter]::ToString($bytes).Replace("-", "") } function ExtractCulterInfoName($asm) { if ($asm.GetName().CultureInfo.TextInfo.CultureName -eq "") { return "neutral" } else { return $asm.GetName().CultureInfo.TextInfo.CultureName } } function CreateBindingElement([System.IO.FileInfo] $fi) { [System.Reflection.Assembly]$asm = [System.Reflection.Assembly]::LoadFile($fi.FullName) $publicKey = ExtractPublicKey $asm $culterInfo = ExtractCulterInfoName $asm $assemblyIdentity = [System.Xml.Linq.XElement]::new($ns1 + "assemblyIdentity") $assemblyIdentity.Add([System.Xml.Linq.XAttribute]::new("name", $asm.GetName().Name)) $assemblyIdentity.Add([System.Xml.Linq.XAttribute]::new("publicKeyToken", $publicKey)) $assemblyIdentity.Add([System.Xml.Linq.XAttribute]::new("culture", $culterInfo)) $bindingRedirect = [System.Xml.Linq.XElement]::new($ns1 + "bindingRedirect") $bindingRedirect.Add([System.Xml.Linq.XAttribute]::new("oldVersion", "0.0.0.0-65535.65535.65535.65535")) $bindingRedirect.Add([System.Xml.Linq.XAttribute]::new("newVersion", $asm.GetName().Version<#$fi.VersionInfo.FileVersion#>)) return [System.Xml.Linq.XElement]::new($ns1 + "dependentAssembly", $assemblyIdentity, $bindingRedirect) } function UpdateBindings([string] $webConfigPath, [string] $packageConfigPath, [string] $binPath) { $webConfig = [System.Xml.Linq.XDocument]::Load($webConfigPath) ClearBindings $webConfig [System.Xml.Linq.XDocument] $packageConfig = [System.Xml.Linq.XDocument]::Load($packageConfigPath) $packages = GetPackageList $packageConfig $binPath [System.Xml.Linq.XElement]$assemblyBinding = $webConfig.Root.Element("runtime").Element($ns1 + "assemblyBinding") $packages | ForEach-Object { [System.IO.FileInfo]$fi = [System.IO.FileInfo]::new($_) if ($fi.Exists) { $newElement = CreateBindingElement $fi $assemblyBinding.Add($newElement) } } $webConfig.Save($webConfigPath) } function LoadWindowsFormsAssembly() { if (!$isWindowsFormsAssemblyLoaded) { [void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') $isWindowsFormsAssemblyLoaded = $true } } function PromptForFile ([string]$title, [string]$filter) { LoadWindowsFormsAssembly [System.Windows.Forms.OpenFileDialog]$dialog = New-Object System.Windows.Forms.OpenFileDialog $dialog.Multiselect = $false $dialog.Title = $title $dialog.Filter = $filter if ($dialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) { return $dialog.FileName } else { return $null } } function PromptForDirectory ([string]$title) { LoadWindowsFormsAssembly [System.Windows.Forms.FolderBrowserDialog]$dialog = New-Object System.Windows.Forms.FolderBrowserDialog if ($dialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) { return $dialog.SelectedPath } else { return $null } } function MessageBox([string]$title) { LoadWindowsFormsAssembly [System.Windows.Forms.MessageBox]::Show($title) } if ([System.String]::IsNullOrEmpty($webConfigPath)) { $webConfigPath = PromptForFile 'Please select the web.config file' '.NET Configuration File (web.config)|web.config' if ([System.String]::IsNullOrEmpty($webConfigPath)) {exit} } if ([System.String]::IsNullOrEmpty($packagesConfigPath)) { $packagesConfigPath = PromptForFile 'Please select the packages.config file' 'NuGet Package File (packages.config)|packages.config' if ([System.String]::IsNullOrEmpty($packagesConfigPath)) {exit} } if ([System.String]::IsNullOrEmpty($binPath)) { $binPath = PromptForDirectory "Please select your application BIN directory" if ([System.String]::IsNullOrEmpty($binPath)) {exit} } UpdateBindings $webConfigPath $packagesConfigPath $binPath 
0
source share

All Articles