nuget - Nuget Restore 在不同位置创建包文件夹
问题描述
我有一个包含类库的解决方案 A,它有一个 package.config。当我使用 Nuget 还原选项时,它会正确地重新创建包文件夹并且引用正常。问题出现在另一个解决方案 B 中,我添加了项目 A,当我尝试 Nuget Restore 时,它在解决方案 B 目录中创建了 packages 文件夹,而项目 A 找不到丢失的引用。如何使解决方案 B 恢复项目 A 目录中项目 A 所需的包?
解决方案
TL;DR: Try running Update-Package -Reinstall
from the Package Manager Console.
The only way I know for this to happen is when a project that uses packages.config
for NuGet references is moved to a new directory with a different relative path to the solution. packages.config
is basically "non-integrated" package management. Anyone using .NET since the beginning will remember when there was no NuGet and you'd need to add assembly references directly to dlls. packages.config
automates this, but means that when the path to the solution packages folder changes, the references are no longer valid. NuGet doesn't know this and always restores to the solution packages folder. So, you need to update the project to point correctly to the solution packages folder. You can do it manually by editing your project file, by uninstalling and re-installing all the packages one-by-one, or use PMC's Update-Package
to do it.
PackageReference doesn't have this problem, as the path to the restored packages is not stored in the project, so even if your project moves around, worst case all you need to do is restore again, but often even that's not needed. So, I recommend you migrate from packages.config
to PackageReference
if you can, but see the docs because there are package compatibility issues to be aware of. Basically, if you use packages with content that gets copied into your project on install, you need to stick with packages.config
. Otherwise PackageReference
gives a better experience to almost everyone else.
推荐阅读
- r - R试图在因子变量上获得频率输出,但仅适用于存在的值,而不是存在的每个因子标签
- notifications - 在哪里可以找到“Visual Studio 通知窗口”的文档?
- here-api - 无法使用我的 api 密钥在此处成功发出地图请求
- python - 如何使用 Xlsxwriter 更改字符串中的某种字体颜色?
- sql - 需要 SQL 中以下结果集的结果集
- python - 更改从 CSV 上传的 Pandas DataFrame 上的数据类型 - 主要是 Object 到 Datetime
- python - 在python中用for循环改变二维列表
- uwp - 如何在 UWP 中包装 ToggleSwitch 的 OffContent/OnContent?
- python - 在存储过程中使用输入参数作为关键字
- java - 我们何时以及为什么需要 ApplicationRunner 和 Runner 接口?