NuGet 还原无法从本地存储库还原包



从全局 nuget-repository 还原

我有这个包.config-file:

<?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 包,这些包列在上面的包.config 中:

nuget restore packages.config -PackagesDirectory NuGetPackages -NoCache

这很好用。

此示例的所有文件都可以在这里找到: https://github.com/ezeh2/nuget_restore_examples/tree/master/nuget_with_global_nuget_repository

从本地 nuget 存储库还原

在我的公司中,我们必须使用位于网络共享上的存储库。 并且我们不允许从标准的全局 nuget 存储库进行包还原。

出于演示目的,我们假设本地包存储库位于目录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_downloaduget\NuGetPackagesSource: 在源 'C:\software_downloaduget\NuGetPackagesSource' 上找不到包 'jQuery.3.1.1'。

将包"NLog.4.3.10"添加到文件夹"C:\software_downloaduget\NuGetPackages" 将包"NLog.4.3.10"添加到文件夹"C:\software_downloaduget\NuGetPackages">

包.config 项目中的错误 找不到包"jQuery"的版本"3.1.1"。 C:\software_downloaduget\NuGetPackagesSource: 在源 'C:\software_downloaduget\NuGetPackagesSource' 上找不到包 'jQuery.3.1.1'。

从错误消息包中看到,jquery 无法恢复。但是包 NLog 已成功还原。我没有解释 这种行为,因为软件包jqueryNLog都在本地软件包存储库中。

此示例的所有文件都可以在这里找到: https://github.com/ezeh2/nuget_restore_examples/tree/master/nuget_with_local_nuget_repository

仔细查看您的软件包存储库。NLog包直接位于NuGetPackagesSource的下方 而jquery-package在路径jquery/3.1.1/jquery.3.1.1.nupkg中。您使用不同的文件夹结构 包NLogJquery。如果nuget看到NuGetPackagesSource正下方的 nupkg 文件,则假定 所有 nupkg-file 都在同一级别,它不会在NuGetPackagesSource下的文件夹中搜索。这 这就是为什么得到错误Unable to find version '3.1.1' of package 'jQuery',即使jquery包在那里。

如何解决此问题

摆脱你的NuGetPackagesSource-文件夹,并使用如下nuget install从头开始构建它:

nuget installjQuery-Version 3.3.1 -OutputDirectory NuGetPackagesSource

nuget installNLog-版本 4.3.10 -输出目录 NuGetPackagesSource

替代解决方案

将所有 nupkg 文件直接放在 NuGetPackagesSource 下,不要使用 根本nuget install。但这仅适用于没有其他文件夹的简单包。不幸的是,这不能用NLogJQuery来完成。

最新更新