2011-10-14 10 views
36

Ho una versione x86 e x64 di un file binario che voglio caricare su NuGet. Qual è il consiglio o il metodo richiesto per creare/caricare quel pacchetto? Non posso find much basare la mia decisione su. Vedo due metodi ...Come devo creare o caricare un pacchetto NuGet a 32 e 64 bit?

  1. entrambi UPLOAD nello stesso pacchetto
    • Quale dovrei installare di default?
    • C'è un modo per testare l'architettura del processore del progetto per prendere la decisione?
  2. Carica due pacchetti separati

Domanda bonus: cosa succede se sto usando qualcosa come Chocolatey, che avvolge NuGet con il pacchetto gestore semantica? Potrei aver bisogno/voglio i pacchetti x86 e x64 installati sul mio sistema.

+3

Se vi capita di avere questo problema troppo, si prega di up-voto questo lavoro prodotto NuGet: http://nuget.codeplex.com/workitem/679 –

+0

Esistono aggiornamenti su questo problema? – Sjoerd222888

+0

Lasciatemi aggiornare la domanda e, almeno, la mia risposta.Perché credo che stavo chiedendo sui pacchetti cioccolatoso quando era molto giovane e non ha avuto le caratteristiche di robustezza a 32 e 64 bit costruiti nel –

risposta

11

Siamo stati discussing un problema simile sul Chocolatey Google Group. Non ci sono semantiche integrate in NuGet. Il requisito non sarebbe, , quale architettura di processore stai eseguendo su. Dovrebbe essere quale architettura del processore è il tuo progetto di targeting. E poi questo complica le cose ... dovresti capire anche AnyCPU.

Penso che per ora, ho intenzione di caricare due pacchetti. Posso sempre pubblicare uno combinato quando aggiusto uno install.ps1 che può gestire l'interrogazione della destinazione del progetto.

mypackage.x86 
mypackage.x64 
+1

Se vi capita di avere questo problema troppo, si prega di up-voto questo lavoro prodotto NuGet.: http://nuget.codeplex.com/workitem/679 –

+1

faccio due pacchetti, una specie di dolore, ho sollevato la questione un po 'indietro anche: http://nuget.codeplex.com/discussions/400682#post931990 – eschneider

0

Non sembra essere un obiettivo specifico per architetture a 32 o 64 bit. Un po 'di dolore, ma puoi fare qualcosa con gli script di PowerShell (install.ps1) per rilevare l'architettura e installarla di conseguenza?

vedere Esecuzione automatica di script PowerShell durante l'installazione e la rimozione del pacchetto - http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package

13

È possibile aggiungere il supporto x64 e x86 a un progetto utilizzando riferimenti condizionali. Sembrerebbe che per ora a Nuget non piaccia avere due riferimenti con lo stesso nome. Quindi dobbiamo aggiungere manualmente il secondo riferimento e quindi rendere i riferimenti condizionali.

Salvare assiemi x64 in una cartella denominata x64 & assembly x86 in una cartella denominata x86 Entrambi devono avere lo stesso nome assembly. Quindi aggiornare l'array allowedReferences con i nomi di tutti gli assembly da aggiungere.

Utilizzare i seguenti script.

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

questo è stato di grande aiuto, grazie. – 0x1mason

Problemi correlati