nuget-package - nuget restore 无法从本地存储库还原包
问题描述
从全局 nuget 存储库恢复
我有这个 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-packages:
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
解决方案
仔细查看您的包存储库。-packageNLog
直接在下面NuGetPackagesSource
,而jquery-package
在 path 中jquery/3.1.1/jquery.3.1.1.nupkg
。您对包NLog
和Jquery
. 如果nuget直接在下面看到一个 nupkg 文件,NuGetPackagesSource
它会假定所有 nupkg 文件都在同一级别上,并且它不会在下面的文件夹中搜索NuGetPackagesSource
。这就是为什么会出现错误Unable to find version '3.1.1' of package 'jQuery'
,即使jquery
-package 在那里。
如何解决此问题
摆脱您的NuGetPackagesSource
-folder 并从头开始重新构建它,nuget install
如下所示:
nuget install
jQuery
-Version 3.3.1 -OutputDirectory NuGetPackagesSourcenuget install
NLog
-Version 4.3.10 -OutputDirectory NuGetPackagesSource
替代解决方案
将所有 nupkg 文件直接放在 NuGetPackagesSource 下,根本不要使用
nuget install
。但这仅适用于没有额外文件夹的简单包。不幸的是,这不能用NLog
and来完成JQuery
。
推荐阅读
- botframework - 使用空格访问属性 - 发送 HTTP 请求
- gatsby - 有没有办法在 Gatsby 中修改 MDX frontmatter?
- node.js - Mongo Compass 无法连接到我的服务器。NodeJS 和 shell 工作
- android - 在 React Native 中将图像添加到 FormData 结构时,Axios POST 请求会出现“网络错误”
- python - 我怎样才能循环这段代码直到等于零?
- list - 在 Kotlin 中按分隔符拆分列表
- python - 查找数据集中上升和下降值的差异
- java - java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory 错误
- vb.net - 复制的文本框在 IDE 中不可见
- docker - FastAPI gunicorn 添加日志时间戳