7

Tôi có gói NuGet nội bộ chứa một dll đơn, không phụ thuộc gói NuGet bên ngoài và không có biến đổi web.config.Nuget Update-Package không chính xác cập nhật chuyển hướng ràng buộc lắp ráp

Tuy nhiên, khi tôi chạy Update-Package vào các dự án của tôi (lớp lib và trang web) cho NuGet cụ thể này, nó sẽ tự động được cập nhật trang web của tôi web.config ← liên kết lắp ráp ràng buộc để phiên bản cũ của System.Web.Mvc và Newtonsoft .Json. Trang web web.config hiện có chúng ràng buộc với phiên bản mới nhất đang được sử dụng.

Sử dụng GUI, sử dụng Quản lý gói NuGet cho Giải pháp ... Tôi chọn CẬP NHẬT NuGet này cho các dự án có thể có tham chiếu đến phiên bản cũ. Sau đó chọn Cập nhật

Đây là kết quả từ Package Manager: http://pastebin.com/3ySwTRFR

Và web.config của tôi đã đi từ:

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

Để:

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

Các gói NuGet Tôi đang cập nhật có một dll tham khảo Newtonsoft.Json (nhưng không rõ ràng là đã làm phụ thuộc gói NuGet)

Khi không biết nhà phát triển cập nhật gói NuGet này, nó sẽ phá vỡ thời gian chạy tìm phiên bản cũ của MVC hoặc JSON.NET dll.

Trước đây tôi đã cố gắng sử dụng -IgnoreDependencies powershell command switch, nhưng điều này dường như không ảnh hưởng đến vấn đề này.

Bất kỳ ý tưởng nào về những gì có thể chuyển đổi web.configs của tôi (không có biến đổi rõ ràng) trong gói cập nhật?

Chỉnh sửa: VS2015 w/NuGet 3.3.0 có vẻ hoạt động tốt hơn ... trong khi cập nhật gói ngẫu nhiên, nó tìm thấy một chuyển hướng ràng buộc BAD cũ và sửa nó! enter image description here

Trả lời

7

Skip áp dụng đổi hướng liên kết là một lựa chọn bây giờ trong NuGet 3.3.0: Issue #1147

enter image description here

0

Tôi có một giải pháp tốt hơn. Bởi vì tôi hoàn toàn điên rồ khi phải cập nhật hơn 72 tài liệu tham khảo mỗi khi tôi cập nhật các gói của mình, tôi đã phát triển một kịch bản PowerShell cập nhật Web.Config của bạn dựa trên các gói trong packages.config và các tệp DLL bạn đã xuất bản trong BIN danh mục.

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, lệnh điều khiển gói Add-BindingRedicrect không hoạt động. Nó chỉ cập nhật 3 trong số 72 gói được tham chiếu. Kịch bản mà tôi cung cấp đi qua tất cả chúng và hành động trên bất kỳ pacakges nào trong "packages.config" trừ khi DLL tồn tại trong thư mục BIN. – RashadRivera

Các vấn đề liên quan