简体   繁体   English

NuGet CLI源命令未更新NuGet.Config

[英]NuGet.Config isn't updated by the nuget CLI sources command

I created a nuget package using dotnet pack , and turned a local directory into a feed using 我使用dotnet pack创建了一个nuget包,并使用

nuget sources add -Name My.Namespace -Source /full/path/to/the/packages

and then added the package to the feed 然后将包添加到Feed中

nuget add bin/Debug/My.Namespace.0.0.0.nupkg -source /full/path/to/the/packages

nuget sources list shows this local feed as expected: 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

and the directory structure of packages is correct 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

But dotnet repeatedly fails to add the package to projects 但是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'.

And manually adding the package to the .csproj errors when I try to build: 并在尝试构建时手动将软件包添加到.csproj错误:

error NU1101: Unable to find package My.Namespace. No packages exist with this id in source(s): nuget.org

Looks like dotnet isn't checking my local NuGet feeds, so I inspected ~/.nuget/NuGet/NuGet.Config which only contains 好像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>

Why isn't my local feed here? 为什么我的本地提要不在这里?

How can I get it to appear here? 如何让它出现在这里? (Ideally so that I won't have to manually edit this file every time...) (理想情况下,这样我就不必每次都手动编辑此文件...)

Or, if the reason I can't add my package to my other project is unrelated, how am I meant to locally create and depend on NuGet packages? 或者,如果无法将程序包添加到其他项目的原因无关,那么我应该在本地创建并依赖NuGet程序包吗?

The command line to add a package source will, by default, add it to the file in the path %appdata%\\NuGet\\nuget.config . 默认情况下,用于添加程序包源的命令行会将其添加到路径%appdata%\\NuGet\\nuget.config的文件中。 If you want to modify a specific Nuget config file, you can specify which one by using the -ConfigFile option, for example: 如果要修改特定的Nuget配置文件,可以使用-ConfigFile选项指定哪个文件,例如:

nuget sources add -Name My.Namespace -ConfigFile /path/to/config -Source /path/to/packages

I'm making a guess that Nuget is finding the config file in ~/.nuget/NuGet/NuGet.Config and stops searching for more. 我正在猜测Nuget在~/.nuget/NuGet/NuGet.Config找到配置文件,并停止搜索更多文件。

Note, if the Nuget configuration you require is only specific to the project you are working with, then I would recommend placing a nuget.config file in the root of your solution folder. 请注意,如果您所需的Nuget配置仅特定于您正在使用的项目,那么我建议您在解决方案文件夹的根目录中放置一个nuget.config文件。

You can find info on the config file locations here . 您可以在此处找到有关配置文件位置的信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM