gpt4 book ai didi

c# - NuGet.Config 未由 nuget CLI sources 命令更新

转载 作者:太空宇宙 更新时间:2023-11-03 14:40:06 24 4
gpt4 key购买 nike

我使用 dotnet pack 创建了一个 nuget 包,并使用

将本地目录转换为提要
nuget sources add -Name My.Namespace -Source /full/path/to/the/packages

然后将包添加到提要

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 '/Users/theonlygusti/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 文件放在解决方案文件夹的根目录中。

您可以找到有关配置文件位置的信息 here .

关于c# - NuGet.Config 未由 nuget CLI sources 命令更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57430814/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com