【问题标题】:nuget restore is unable to restore packages from local repositorynuget restore 无法从本地存储库还原包
【发布时间】: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 已成功恢复。我没有解释 因为这两个包jqueryNLog 都在本地包存储库中。

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

【问题讨论】:

    标签: nuget-package nuget-package-restore


    【解决方案1】:

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

    如何解决此问题

    删除您的NuGetPackagesSource-文件夹并使用nuget install 从头开始​​构建它,如下所示:

    nuget install jQuery -Version 3.3.1 -OutputDirectory NuGetPackagesSource

    nuget install NLog -Version 4.3.10 -OutputDirectory NuGetPackagesSource

    替代解决方案

    将所有 nupkg 文件直接放在 NuGetPackagesSource 下,不要使用 nuget install 在所有。但这仅适用于没有额外文件夹的简单包。不幸的是,NLogJQuery 无法做到这一点。

    【讨论】:

      猜你喜欢
      • 2016-03-13
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多