我们正在寻找运行私有NuGet服务器。我知道像ProGet这样的产品具有从NuGet获取包并将它们放入私有源的功能。如果可能的话,我们对裸骨方法更感兴趣。我使用NuGet.Server和Visual Studio构建和部署了NuGet服务器。我可以将nupkg文件放入我的packages文件夹,然后从我的私有服务器安装到Visual Studio项目中。我不得不手动下载NuGet包,然后复制nupkg文件。这是唯一的方法吗?似乎有些NuGet软件包不能作为独立软件包完全下载。我能够通过创建一个虚拟应用程序,从nuget.org安装包然后复制nupkg文件来获得一个,但这看起来很糟糕。
任何运行私有NuGet服务器的人都有一种更简洁的方法将nuget.org中的软件包“复制”到他们的私人服务器中?
TIA
答案 0 :(得分:0)
过去遇到同样的问题,我使用了Blog Post by Jon Galloway
它包含一个“开箱即用”的脚本(现在在Win7上双重检查)
注意变量,因为默认脚本存储库是Microsoft的,并将自己限制为500个nuget包。
另外,在下载软件包时,我注意到它们保存在“.Version.nupkg”中,并且不包含完整的软件包名称(发生在Nuget官方软件库https://www.nuget.org/api/v2/中)
编辑:
在您需要选择特定的nuget包之后,我添加了几行来过滤包
param(
[parameter(Mandatory=$TRUE,Position=0)]
$PackageFilterBy
)
# --- settings ---
$feedUrlBase = "http://go.microsoft.com/fwlink/?LinkID=206669"
# the rest will be params when converting to funclet
$latest = $true
$overwrite = $false
$top = 500 #use $top = $null to grab all
$destinationDirectory = join-path ([Environment]::GetFolderPath("MyDocuments")) "NuGetLocal"
# --- locals ---
$webClient = New-Object System.Net.WebClient
# --- functions ---
# download entries on a page, recursively called for page continuations
function DownloadEntries {
param ([string]$feedUrl)
$feed = [xml]$webClient.DownloadString($feedUrl)
$entries =@()
$filter = $PackageFilterBy.Split(',')
foreach($item in $filter ){
$feed.feed.entry | %{if($_.id -match "$item"){$entries += $_}}
}
$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 = GetPackageUrl($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
}
使用脚本将是这样的:。\ Script.ps1 jquery,Microsoft