从全局nuget-repository恢复
我有这个packages.config文件:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="jQuery" version="3.1.1" targetFramework="net46" />
<package id="NLog" version="4.3.10" targetFramework="net46" />
</packages>
使用此命令,我可以恢复nuget-packages,它们在上面的packages.config中列出:
nuget restore packages.config -PackagesDirectory NuGetPackages -NoCache
这很好用 .
可以在此处找到此示例的所有文件:https://github.com/ezeh2/nuget_restore_examples/tree/master/nuget_with_global_nuget_repository
从本地nuget-repository恢复
在我的公司,我们必须使用位于网络共享上的存储库 . 我们不允许从标准的全局nuget-repository进行包恢复 .
出于演示目的,我们假设本地package-repository位于 NuGetPackagesSource
目录中,这是它的内容:
-NuGetPackagesSource
|-jquery
|-3.1.1
|-jquery.3.1.1.nupkg
|-jquery.3.1.1.nupkg.sha512
|-jquery.nuspec
|-nlog.4.3.10.nupkg
使用此NuGet.Config,我们确保使用本地package-repository而不是全局package-repository:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<disabledPackageSources>
<add key="nuget.org" value="true" />
</disabledPackageSources>
<packageSources>
<add key="my" value="NuGetPackagesSource" />
</packageSources>
</configuration>
以下从本地目录 NuGetPackagesSource
进行还原:
nuget restore packages.config -ConfigFile NuGet.config -PackagesDirectory NuGetPackages -NoCache
不幸发生以下错误:
警告:无法找到包'jQuery'的版本'3.1.1' . C:\ software_download \ nuget \ NuGetPackagesSource:在源'C:\ software_download \ nuget \ NuGetPackagesSource'上找不到包'jQuery.3.1.1' . 将软件包'NLog.4.3.10'添加到文件夹'C:\ software_download \ nuget \ NuGetPackages'将软件包'NLog.4.3.10'添加到文件夹'C:\ software_download \ nuget \ NuGetPackages'packages.config项目中的错误无法找到包'jQuery'的版本'3.1.1' . C:\ software_download \ nuget \ NuGetPackagesSource:在源'C:\ software_download \ nuget \ NuGetPackagesSource'上找不到包'jQuery.3.1.1' .
正如您从错误消息包中看到的那样,jquery无法恢复 . 但是包NLog已成功恢复 . 我没有解释这种行为,因为包 jquery
和 NLog
都在本地包存储库中 .
可以在此处找到此示例的所有文件:https://github.com/ezeh2/nuget_restore_examples/tree/master/nuget_with_local_nuget_repository
1 回答
仔细查看您的包存储库 .
NLog
-package直接位于NuGetPackagesSource
下方,而jquery-package
位于路径jquery/3.1.1/jquery.3.1.1.nupkg
中 . 您为包NLog
和Jquery
使用不同的文件夹结构 . 如果 nuget 直接在NuGetPackagesSource
下面看到一个nupkg文件,它会假定所有nupkg文件都在同一级别,并且它不会在NuGetPackagesSource
下面的文件夹中搜索 . 这就是为什么得到错误Unable to find version '3.1.1' of package 'jQuery'
,即使jquery
-package存在 .如何解决此问题
摆脱你的
NuGetPackagesSource
文件夹并使用nuget install
从头开始重新构建它:替代解决方案
将所有nupkg文件直接放在NuGetPackagesSource下,根本不要使用
nuget install
. 但这仅适用于没有其他文件夹的简单包 . 不幸的是,NLog
和JQuery
无法做到这一点 .