我有一個x86和x64版本的二進制文件,我想上傳到NuGet。創建/上傳該軟件包的建議或所需方法是什麼?我不能find much來根據我的決定。我看到兩種方法...我應該如何創建或上傳32位和64位NuGet包?
- 上傳他們都在同一個包
- 哪一個我應該默認安裝?
- 有沒有辦法測試項目的處理器架構來作出決定?
- 上傳兩個獨立的包
獎金的問題:如果我使用類似Chocolatey,它包裝起來的NuGet與包管理器語義?我可能需要/希望在我的系統上安裝x86和x64軟件包。
我有一個x86和x64版本的二進制文件,我想上傳到NuGet。創建/上傳該軟件包的建議或所需方法是什麼?我不能find much來根據我的決定。我看到兩種方法...我應該如何創建或上傳32位和64位NuGet包?
獎金的問題:如果我使用類似Chocolatey,它包裝起來的NuGet與包管理器語義?我可能需要/希望在我的系統上安裝x86和x64軟件包。
我們已經discussing在Chocolatey Google Group類似的問題。 NuGet中沒有內置任何語義。這個要求不會,你在上運行什麼處理器架構。它必須是您的項目所針對的處理器架構。然後,這使複雜的事情......你必須瞭解AnyCPU
以及。
我想現在,我打算上傳兩個軟件包。當我修復一個install.ps1
可以處理查詢項目目標時,我總是可以發佈一個組合。
mypackage.x86
mypackage.x64
如果您碰巧遇到了這個問題,請將此作品投加NuGet項目: http://nuget.codeplex.com/workitem/679 –
我做了兩個包,有點痛,我提出這個問題一會兒也回來了:http://nuget.codeplex.com/discussions/400682#post931990 – eschneider
似乎沒有32位或64位體系結構的特定目標。痛苦的一點,但你可以用PowerShell腳本(install.ps1)來做些什麼來檢測體系結構並進行相應的安裝?
請參閱自動運行PowerShell腳本在軟件包安裝和刪除 - http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package
您可以使用條件引用將x64和x86支持添加到項目中。現在看來,Nuget不喜歡有兩個同名的引用。所以我們需要手動添加第二個參考,然後使參考有條件。
將x64程序集保存在名爲x64的文件夾中& x86程序集名爲x86的文件夾它們必須具有相同的程序集名稱。然後使用要添加的所有程序集的名稱更新allowedReferences數組。
使用以下腳本。
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)
}
}
這個是一個很大的幫助,謝謝。 – 0x1mason
如果您正好有這個問題也請贊成票這項工作的NuGet項目:http://nuget.codeplex.com/workitem/679 –
這個問題有沒有更新? – Sjoerd222888
讓我更新這個問題,至少,我的答案。因爲我相信自己在問及巧克力包的時候非常年輕,並且沒有內置強大的32位和64位功能。 –