7

Ho un pacchetto NuGet interno che contiene una singola DLL, nessuna dipendenza esterna del pacchetto NuGet e nessuna trasformazione web.config.Pacchetto aggiornamento Nuget che aggiorna in modo non corretto i reindirizzamenti dell'associazione

Eppure, quando ho eseguito Update-pacchetto sui miei progetti (classe lib e sito web) per questo specifico NuGet, si sta aggiornando automaticamente il mio sito web.config redirect assemblaggio vincolanti per vecchie versioni di System.Web.Mvc e Newtonsoft .json. Il sito web.config li ha attualmente vincolati all'ultima versione utilizzata.

Utilizzo della GUI, utilizzo dei pacchetti di gestione NuGet per la soluzione ... Ho scelto di AGGIORNARE questo NuGet per i progetti applicabili che hanno un riferimento alla versione precedente. Poi scegli Aggiornamento

Ecco l'output del Package Manager: http://pastebin.com/3ySwTRFR

E il mio web.config è passato da:

<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> 

A:

<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> 

Il pacchetto NuGet sto aggiornando ha una DLL che fa riferimento a Newtonsoft.Json (ma non è esplicitamente creata una dipendenza del pacchetto NuGet)

Quando lo sviluppatore inconsapevole aggiorna questo pacchetto NuGet, interrompe il runtime alla ricerca della vecchia versione delle DLL MVC o JSON.NET.

In passato ho tentato di utilizzare lo -IgnoreDependencies powershell command switch, ma questo sembra non avere alcun impatto sul problema.

Qualche idea su cosa potrebbe trasformare il mio web.configs (senza una trasformazione esplicita) durante il pacchetto di aggiornamento?

Modifica: VS2015 con NuGet 3.3.0 sembra comportarsi meglio ... durante l'aggiornamento casuale del pacchetto ha rilevato un vecchio reindirizzamento del binding BAD e lo ha corretto! enter image description here

risposta

7

Skip applicando redirect vincolanti è un'opzione ora in NuGet 3.3.0: Issue #1147

enter image description here

0

ho una soluzione migliore. Perché sono assolutamente pazzo quando devo aggiornare oltre 72 riferimenti ogni volta che aggiorno i miei pacchetti, ho sviluppato uno script PowerShell che aggiorna il tuo Web.Config basato sui pacchetti nel tuo packages.config e le DLL che hai pubblicato nel BIN directory.

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's BIN directory" 
    if ([System.String]::IsNullOrEmpty($binPath)) {exit} 
} 


UpdateBindings $webConfigPath $packagesConfigPath $binPath 
+0

BTW, il comando della console del pacchetto Add-BindingRedicrect non funziona. Aggiorna solo 3 su 72 pacchetti di riferimento. Lo script che ho fornito passa attraverso tutti loro e agisce su qualsiasi pacak in "packages.config" a meno che la DLL non esista nella directory BIN. – RashadRivera