![](/img/trans.png)
[英]How to get the list of all the packages with their versions from Artifacts/Nuget Feed in Azure Devops using C#?
[英]Download all packages from private nuget feed
我想从我的私人 nuget 提要中下载所有版本的所有软件包。 而已。 我在使用 powershell、bash、package 管理器方面没有任何问题。
我不能使用占位符项目 - 引用所有包并复制我的缓存,因为我需要所有版本。
任何想法?
我正在使用私人 nuget-feed。 饲料有点坏了,但我无法修复它。 所以我必须以这种方式 go ...
我在这里创建了一个更好的 PowerShell,可以下载所有版本的所有软件包
Find-Package -AllVersions -Source NuGet-Source | ForEach-Object {
Install-Package -Name $_.Name -MaximumVersion $_.Version -Destination 'C:\Temp\Nuget\' -Source NuGet-Source -SkipDependencies
}
使用 PowerShell,您可以执行以下操作:
>Find-Package -Name='Package_Name' -AllVersions -Source Local | Install-Package -Destination 'C:\SOME_PATH'
该命令将在源本地(必须在 NuGet.config 中指定)中查找名称为“Package_Name”的所有版本的包,并将它们安装到“C:\\SOME_PATH”文件夹中。 要从源中获取所有包,请删除-Name
参数。
然后您可以从其自己的文件夹中获取每个 .nupkg 文件。
如果你只是想下载,那么save-package比install-package更合适
此脚本将所有 nuget 包从 nuget 服务器 (NuGet-Source) 保存到当前目录中
Find-Package -AllVersions -Source NuGet-Source | ForEach-Object {
Save-Package -Name $_.Name -RequiredVersion $_.Version -Source NuGet-Source -Path '.'
}
这些解决方案对我不起作用,所以以下是我所做的。 我正在努力将 TFS 2017 提要迁移到 Azure DevOps 托管提要。
首先,我使用 Powershell ISE 中的此脚本从本地自托管源下载了所有包:
# --- settings ---
# use nuget v2 feed for this script
# v2 feed is sometimes same url as v3, just change /v3/index.json to /v2/
$feedUrlBase = "http://servername:8080/tfs/MOMCollection/_packaging/bbd0bd78-205f-48af-ac25-6eef6470adb4/nuget/v2/" # be sure to include trailing slash
# the rest will be params when converting to funclet
$latest = $false
$overwrite = $true
$top = $null #use $top = $null to grab all , otherwise use number
$destinationDirectory = join-path ([Environment]::GetFolderPath("MyDocuments")) "NuGetLocal"
# --- locals ---
$webClient = New-Object System.Net.WebClient
# following is required if authenticating to TFS using integrated credentials
$webClient.UseDefaultCredentials=$true
# --- functions ---
# download entries on a page, recursively called for page continuations
function DownloadEntries {
param ([string]$feedUrl)
$feed = [xml]$webClient.DownloadString($feedUrl)
$entries = $feed.feed.entry
$progress = 0
foreach ($entry in $entries) {
$url = $entry.content.src
$fileName = $entry.properties.id + "." + $entry.properties.version + ".nupkg"
$saveFileName = join-path $destinationDirectory $fileName
$pagepercent = ((++$progress)/$entries.Length*100)
if ((-not $overwrite) -and (Test-Path -path $saveFileName))
{
write-progress -activity "$fileName already downloaded" `
-status "$pagepercent% of current page complete" `
-percentcomplete $pagepercent
continue
}
write-progress -activity "Downloading $fileName" `
-status "$pagepercent% of current page complete" `
-percentcomplete $pagepercent
[int]$trials = 0
do {
try {
$trials +=1
$webClient.DownloadFile($url, $saveFileName)
break
} catch [System.Net.WebException] {
write-host "Problem downloading $url `tTrial $trials `
`n`tException: " $_.Exception.Message
}
}
while ($trials -lt 3)
}
$link = $feed.feed.link | where { $_.rel.startsWith("next") } | select href
if ($link -ne $null) {
# if using a paged url with a $skiptoken like
# http:// ... /Packages?$skiptoken='EnyimMemcached-log4net','2.7'
# remember that you need to escape the $ in powershell with `
return $link.href
}
return $null
}
# the NuGet feed uses a fwlink which redirects
# using this to follow the redirect
function GetPackageUrl {
param ([string]$feedUrlBase)
$resp = [xml]$webClient.DownloadString($feedUrlBase)
return $resp.service.GetAttribute("xml:base")
}
# --- do the actual work ---
# if dest dir doesn't exist, create it
if (!(Test-Path -path $destinationDirectory)) {
New-Item $destinationDirectory -type directory
}
# set up feed URL
$serviceBase = $feedUrlBase
$feedUrl = $serviceBase + "Packages"
if($latest) {
$feedUrl = $feedUrl + "?`$filter=IsLatestVersion eq true"
if($top -ne $null) {
$feedUrl = $feedUrl + "&`$orderby=DownloadCount desc&`$top=$top"
}
}
while($feedUrl -ne $null) {
$feedUrl = DownloadEntries $feedUrl
}
接下来,我验证了每个 package 的每个版本都以 .nupkg 格式下载,并且它们是。 接下来我使用 powershell 上传到新提要:
$destinationDirectory = join-path ([Environment]::GetFolderPath("MyDocuments")) "NuGetLocal"
Get-ChildItem $destinationDirectory -Recurse -Filter *.nupkg |
Foreach-Object {
nuget push -Source "YOUR NUGEFEED NAME HERE" -ApiKey az $_.FullName
}
我希望这对正在迁移 nuget 提要的人有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.