2011-10-14 32 views
36

Tôi có phiên bản x86 và x64 của một tệp nhị phân mà tôi muốn tải lên NuGet. Đề xuất hoặc phương pháp bắt buộc để tạo/tải lên gói đó là gì? Tôi không thể find much để đưa ra quyết định của mình. Tôi thấy hai phương pháp ...Tôi nên tạo hoặc tải lên gói NuGet 32 ​​bit và 64 bit như thế nào?

  1. Tải lên cả hai trong cùng một gói
    • Cái nào tôi nên cài đặt theo mặc định?
    • Có cách nào để kiểm tra kiến ​​trúc bộ vi xử lý của dự án để đưa ra quyết định không?
  2. Tải lên hai gói riêng biệt

Bonus câu hỏi: Nếu tôi đang sử dụng một cái gì đó giống như Chocolatey, mà kết thúc tốt đẹp NuGet với ngữ nghĩa quản lý gói? Tôi có thể cần/muốn các gói x86 và x64 được cài đặt trên hệ thống của tôi.

+3

Nếu bạn tình cờ có vấn đề này quá, xin vui lòng up-phiếu công việc này NuGet mục: http://nuget.codeplex.com/workitem/679 –

+0

Có bất kỳ cập nhật nào về vấn đề này không? – Sjoerd222888

+0

Hãy để tôi cập nhật câu hỏi và, ít nhất, câu trả lời của tôi.Bởi vì tôi tin rằng tôi đã hỏi về các gói Chocolatey khi nó còn rất trẻ và không có các tính năng 32 và 64 bit mạnh mẽ được xây dựng. –

Trả lời

11

Chúng tôi đã discussing một vấn đề tương tự trên Chocolatey Google Group. Không có bất kỳ ngữ nghĩa nào được xây dựng trong NuGet. Yêu cầu sẽ không được, kiến ​​trúc bộ vi xử lý nào bạn đang chạy trên. Nó sẽ phải là kiến ​​trúc bộ vi xử lý nào là nhắm mục tiêu dự án của bạn. Và sau đó điều đó làm phức tạp ... bạn cũng cần phải hiểu rõ AnyCPU.

Tôi nghĩ bây giờ, tôi sẽ tải lên hai gói. Tôi luôn có thể xuất bản kết hợp khi tôi sửa một số install.ps1 có thể xử lý truy vấn mục tiêu dự án.

mypackage.x86 
mypackage.x64 
+1

Nếu bạn cũng gặp phải vấn đề này, hãy bỏ phiếu bầu cho mục NuGet công việc này: http://nuget.codeplex.com/workitem/679 –

+1

Tôi thực hiện hai gói, một loại đau, tôi đã nêu ra vấn đề này một lúc nữa: http://nuget.codeplex.com/discussions/400682#post931990 – eschneider

0

Dường như không có mục tiêu cụ thể cho kiến ​​trúc 32 hoặc 64 bit. Bit của một nỗi đau, nhưng bạn có thể làm điều gì đó với các kịch bản PowerShell (install.ps1) để phát hiện kiến ​​trúc và cài đặt cho phù hợp?

Xem Tự động Chạy Scripts PowerShell Trong Lắp đặt trọn gói và diệt - http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package

13

Bạn có thể thêm x64 và hỗ trợ x86 cho một dự án bằng cách sử dụng tài liệu tham khảo có điều kiện. Có vẻ như bây giờ Nuget không thích có hai tham chiếu có cùng tên. Vì vậy, chúng ta cần thêm vào tham chiếu thứ hai theo cách thủ công và sau đó làm cho các tham chiếu có điều kiện.

Lưu tập hợp x64 vào thư mục có tên x64 & cụm x86 trong một thư mục có tên là x86 Cả hai đều phải có cùng tên lắp ráp. Sau đó cập nhật mảng allowedReferences với tên của tất cả các assembly để thêm vào.

Sử dụng các tập lệnh sau.

Install.ps1

$allowedReferences = @("Noesis.Javascript") 

# Full assembly name is required 
Add-Type -AssemblyName 'Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 

$projectCollection = [Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection 

$allProjects = $projectCollection.GetLoadedProjects($project.Object.Project.FullName).GetEnumerator(); 

if($allProjects.MoveNext()) 
{ 
    $currentProject = $allProjects.Current 

    foreach($Reference in $currentProject.GetItems('Reference') | ? {$allowedReferences -contains $_.Xml.Include }) 
    { 
     $hintPath = $Reference.GetMetadataValue("HintPath") 

     write-host "Matched againt $hintPath" 

     #If it is x64 specific add condition (Include 'Any Cpu' as x64) 
     if ($hintPath -match '.*\\(amd64|x64)\\.*\.dll$') 
     { 
      $Reference.Xml.Condition = "'TargetPlatform' != 'x86'" 

      $condition = $Reference.Xml.Condition 
      write-host "hintPath = $hintPath" 
      write-host "condition = $condition" 

      #Visual Studio doesnt allow the same reference twice (so try add friends) 
      $matchingReferences = $currentProject.GetItems('Reference') | ? {($_.Xml.Include -eq $Reference.Xml.Include) -and ($_.GetMetadataValue("HintPath") -match ".*\\(x86)\\.*\.dll$")} 

      if (($matchingReferences | Measure-Object).Count -eq 0) 
      { 
       $x86 = $hintPath -replace '(.*\\)(amd64|x64)(\\.*\.dll)$', '$1x86$3' 
       $x86Path = Join-Path $installPath $x86 

       if (Test-Path $x86Path) { 
        #Add 
        write-host "Adding reference to $x86" 

        $metaData = new-object "System.Collections.Generic.Dictionary``2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" 
        $metaData.Add("HintPath", $x86) 
        $currentProject.AddItem('Reference', $Reference.Xml.Include, $metaData) 

        $newReference = $currentProject.GetItems('Reference') | ? {($_.Xml.Include -eq $Reference.Xml.Include) -and ($_.GetMetadataValue("HintPath") -eq $x86)} | Select-Object -First 1 

        $newReference.Xml.Condition = "'TargetPlatform' == 'x86'"   
       } 
      } 
     } 

     #If it is x86 specific add condition 
     if ($hintPath -match '.*\\x86\\.*\.dll$') 
     { 
      $Reference.Xml.Condition = "'TargetPlatform' == 'x86'" 

      $condition = $Reference.Xml.Condition 
      write-host "hintPath = $hintPath" 
      write-host "condition = $condition" 

      #Visual Studio doesnt allow the same reference twice (so try add friends) 
      $matchingReferences = $currentProject.GetItems('Reference') | ? {($_.Xml.Include -eq $Reference.Xml.Include) -and ($_.GetMetadataValue("HintPath") -match ".*\\(amd64|x64)\\.*\.dll$")} 

      if (($matchingReferences | Measure-Object).Count -eq 0) 
      { 
       $x64 = $hintPath -replace '(.*\\)(x86)(\\.*\.dll)$', '$1x64$3' 
       $x64Path = Join-Path $installPath $x64 

       if (Test-Path $x64Path) { 
        #Add 
        write-host "Adding reference to $x64" 

        $metaData = new-object "System.Collections.Generic.Dictionary``2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" 
        $metaData.Add("HintPath", $x64) 
        $currentProject.AddItem('Reference', $Reference.Xml.Include, $metaData) 

        $newReference = $currentProject.GetItems('Reference') | ? {($_.Xml.Include -eq $Reference.Xml.Include) -and ($_.GetMetadataValue("HintPath") -eq $x64)} | Select-Object -First 1 

        $newReference.Xml.Condition = "'TargetPlatform' != 'x86'"   
       } else { 
        $amd64 = $hintPath -replace '(.*\\)(x86)(\\.*\.dll)$', '$1amd64$3' 
        $amd64Path = Join-Path $installPath $amd64 

        if (Test-Path $amd64Path) { 
         #Add 
         write-host "Adding reference to $amd64" 

         $metaData = new-object "System.Collections.Generic.Dictionary``2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" 
         $metaData.Add("HintPath", $amd64) 
         $currentProject.AddItem('Reference', $Reference.Xml.Include, $metaData) 

         $newReference = $currentProject.GetItems('Reference') | ? {($_.Xml.Include -eq $Reference.Xml.Include) -and ($_.GetMetadataValue("HintPath") -eq $amd64)} | Select-Object -First 1 

         $newReference.Xml.Condition = "'TargetPlatform' != 'x86'"   
        }    
       }    
      }   
     } 
    } 
} 

Uninstall.ps1

$allowedReferences = @("Noesis.Javascript") 

# Full assembly name is required 
Add-Type -AssemblyName 'Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 

$projectCollection = [Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection 

$allProjects = $projectCollection.GetLoadedProjects($project.Object.Project.FullName).GetEnumerator(); 

if($allProjects.MoveNext()) 
{ 
    foreach($Reference in $allProjects.Current.GetItems('Reference') | ? {$allowedReferences -contains $_.UnevaluatedInclude }) 
    { 
     $allProjects.Current.RemoveItem($Reference) 
    } 
} 
+0

Điều này là một trợ giúp lớn, cảm ơn. – 0x1mason

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