user3310334
user3310334

Reputation:

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

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

and then added the package to the 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:

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

/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 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'.

And manually adding the package to the .csproj errors when I try to build:

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

<?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?

Upvotes: 3

Views: 1039

Answers (1)

DavidG
DavidG

Reputation: 118937

The command line to add a package source will, by default, add it to the file in the path %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 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.

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.

You can find info on the config file locations here.

Upvotes: 1

Related Questions