159

I am wondering where is NuGet.Config file located in Visual Studio 2017 project? I tried to create my own NuGet.Config file in the root of the project, but I didn't find any new repositories (NuGet sources). Does some one have any idea?

Here is the file I am trying to achieve for my .Net Core project:

<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="AspNetCore" value="https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json" /> <add key="AspNetCoreTools" value="https://dotnet.myget.org/F/aspnetcore-tools/api/v3/index.json" /> <add key="NuGet" value="https://api.nuget.org/v3/index.json" /> </packageSources> </configuration> 

5 Answers 5

211

Visual Studio reads NuGet.Config files from the solution root. Try moving it there instead of placing it in the same folder as the project.

You can also place the file at %appdata%\NuGet\NuGet.Config and it will be used everywhere.

https://learn.microsoft.com/en-us/nuget/schema/nuget-config-file

Sign up to request clarification or add additional context in comments.

6 Comments

In Visual Studio 2017 open the solution, then go to tools > options > NuGet Package Manager > Package Source. You should see your sources listed.
By default, VS2017 uses global Nuget.config located at path C:\Users\yourusername\AppData\Roaming\NuGet\Nuget.config
Try not to confuse a nuget.config file with a .nuget folder. NuGet (v3.4.3 and later) silently ignores the entire configuration file if it contains malformed XML (mismatched tags, invalid quotation marks, etc.). This is why it's preferable to manage setting using nuget config ref. It is working at solution level in VS2017 for me.
If you plan to use a CI like Microsoft AppCenter (appcenter.ms) - then it is expecting Nuget.config to the be in the Solution root.
I am not sure why the file NuGet.config was empty when I did the setup on my work laptop, but it was configured properly on my personal laptop. I really wanted to know how this file gets created and under which process? Is it part of the MSBuild Tool Install or part of the NuGet vscode extension install?
|
71

There are multiple nuget packages read in the following order:

  1. First the NuGetDefaults.Config file. You will find this in %ProgramFiles(x86)%\NuGet\Config.
  2. The computer-level file.
  3. The user-level file. You will find this in %APPDATA%\NuGet\nuget.config.
  4. Any file named nuget.config beginning from the root of your drive up to the directory where nuget.exe is called.
  5. The config file you specify in the -configfile option when calling nuget.exe

You can find more information here.

2 Comments

Since it was confusing to me at first, I'd like to clarify: The order listed here is the order in which nuget loads its settings. Later steps potentially override previous settings. So when you specify --configfile ist still reads the default file, the machine-level file etc. But then NuGet considers these options bottom-to-top, i.e. the --configfile wins vs. the user-level file etc.
I am not sure why the file NuGet.config was empty when I did the setup on my work laptop, but it was configured properly on my personal laptop. I really wanted to know how this file gets created and under which process? Is it part of the MSBuild Tool Install or part of the NuGet vscode extension install?
6

If you use proxy, you will have to edit the Nuget.config file.

In Windows 7 and 10, this file is in the path:
C:\Users\YouUser\AppData\Roaming\NuGet.

Include the setting:

<config> <add key = "http_proxy" value = "http://Youproxy:8080" /> <add key = "http_proxy.user" value = "YouProxyUser" /> </config> 

Comments

2

no matter where these files are here is a way to edit them via the dotnet CLI

verify 'file' to get current entries:

dotnet nuget list source 

add new source:

dotnet nuget add source https://nuget.example.com -n SomeName 

Comments

1

In addition to the accepted answer, I would like to add one info, that NuGet packages in Visual Studio 2017 are located in the project file itself. I.e., right click on the project -> edit, to find all package reference entries.

3 Comments

I think you've misunderstood the question. The question is about where do you place the nuget.config file (which lists all the servers which hold available nugets to download). It's not asking which file lists the installed nugets for your project.
@Pure.Krome agree, but it is exciting that the man posted this answer which you think he misunderstood the question, is in fact the man asked the question! ;D
/me hides away, embarassed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.