【发布时间】:2018-05-10 15:32:32
【问题描述】:
从全局 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>
使用此命令,我可以恢复上面 packages.config 中列出的 nuget 包:
nuget restore packages.config -PackagesDirectory NuGetPackages -NoCache
这很好用。
此示例的所有文件都可以在此处找到: https://github.com/ezeh2/nuget_restore_examples/tree/master/nuget_with_global_nuget_repository
从本地 nuget 存储库恢复
在我的公司中,我们必须使用位于网络共享上的存储库。 而且我们不允许从标准的全局 nuget-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,我们确保使用本地包存储库而不是全局包存储库:
<?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
【问题讨论】:
标签: nuget-package nuget-package-restore