我有一个x86和x64版本的二进制文件,我想上传到NuGet。创建/上传该软件包的建议或要求是什么?我不能find much作出决定。我看到两种方法......
奖金问题:如果我使用像Chocolatey这样的东西,它会用包管理器语义包装NuGet怎么办?我可能需要/想要在我的系统上安装x86和x64软件包。
答案 0 :(得分:14)
您可以使用条件引用向项目添加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)
}
}
答案 1 :(得分:12)
我们在discussing上遇到了Chocolatey Google Group类似的问题。 NuGet中没有内置任何语义。要求不是,您运行的处理器架构。它必须是您的项目目标是什么处理器架构。然后这使事情变得复杂......您还必须理解AnyCPU
。
我想现在,我要上传两个包。当我修复一个可以处理查询项目目标的install.ps1
时,我总是可以发布一个组合的。
mypackage.x86
mypackage.x64
答案 2 :(得分:0)
似乎没有针对32位或64位架构的特定目标。有点痛苦,但是你可以用powershell脚本(install.ps1)来检测架构并相应安装吗?
请参阅程序包安装和删除期间自动运行PowerShell脚本 - http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package