我使用
dotnet pack
创建了一个 nuget 包,并使用 将本地目录转换为提要
nuget sources add -Name My.Namespace -Source /full/path/to/the/packages
然后将包添加到 feed 中
nuget add bin/Debug/My.Namespace.0.0.0.nupkg -source /full/path/to/the/packages
nuget sources list
按预期显示此本地提要:
Registered Sources:
1. nuget.org [Enabled]
https://api.nuget.org/v3/index.json
2. My.Namespace [Enabled]
/full/path/to/the/packages
并且
packages
的目录结构是正确的
/full/path/to/the/packages
└── my.namespace
└── 0.0.0
├── my.namespace.0.0.0.nupkg
├── my.namespace.0.0.0.nupkg.sha512
└── my.namespace.nuspec
但是
dotnet
多次无法将包添加到项目中
$ dotnet add package My.Namespace
error: Unable to find package My.Namespace. No packages exist with this id in source(s): nuget.org
error: Package 'My.Namespace' is incompatible with 'all' frameworks in project '~/Documents/Projects/dotnet-core-api/Fun.Project.csproj'.
并在我尝试构建时手动将包添加到
.csproj
错误中:
error NU1101: Unable to find package My.Namespace. No packages exist with this id in source(s): nuget.org
看起来
dotnet
没有检查我本地的 NuGet 源,所以我检查了 ~/.nuget/NuGet/NuGet.Config
,其中仅包含
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
为什么我的本地提要不在这里?
我怎样才能让它出现在这里? (理想情况下这样我就不必每次都手动编辑这个文件......)
或者,如果我无法将包添加到其他项目的原因无关,那么我如何在本地创建并依赖 NuGet 包?
添加包源的命令行默认会将其添加到路径
%appdata%\NuGet\nuget.config
中的文件中。如果要修改特定的 Nuget 配置文件,可以使用 -ConfigFile
选项指定哪个,例如:
nuget sources add -Name My.Namespace -ConfigFile /path/to/config -Source /path/to/packages
我猜测 Nuget 正在
~/.nuget/NuGet/NuGet.Config
中找到配置文件并停止搜索更多内容。
注意,如果您需要的 Nuget 配置仅特定于您正在使用的项目,那么我建议在解决方案文件夹的根目录中放置一个
nuget.config
文件。
您可以在此处找到有关配置文件位置的信息。