133

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>
Richard Garside
  • 87,839
  • 11
  • 80
  • 93
Mohammed Noureldin
  • 14,913
  • 17
  • 70
  • 99

5 Answers5

177

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

Liam
  • 27,717
  • 28
  • 128
  • 190
Justin Emgarten
  • 2,108
  • 1
  • 13
  • 8
  • 1
    In Visual Studio 2017 open the solution, then go to tools > options > NuGet Package Manager > Package Source. You should see your sources listed. – Justin Emgarten Mar 11 '17 at 20:54
  • 18
    By default, VS2017 uses global Nuget.config located at path C:\Users\yourusername\AppData\Roaming\NuGet\Nuget.config – Passenger Oct 25 '17 at 08:00
  • 2
    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](https://learn.microsoft.com/en-us/nuget/consume-packages/configuring-nuget-behavior). It is working at solution level in VS2017 for me. – cadull Dec 06 '18 at 05:00
  • 1
    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. – joehanna Nov 18 '19 at 06:00
  • 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? – tarekahf Feb 13 '22 at 07:18
  • Restart Visual Studio after you move it. It will not automatically pick it up. – Sam Rueby Aug 10 '22 at 20:53
57

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.

Theodore Zographos
  • 2,215
  • 1
  • 24
  • 23
  • 7
    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. – Manuzor Mar 19 '20 at 08:57
  • 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? – tarekahf Feb 13 '22 at 07:18
4

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>
Pang
  • 9,564
  • 146
  • 81
  • 122
Ronaldo Moreira
  • 1,007
  • 7
  • 3
3

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.

Mohammed Noureldin
  • 14,913
  • 17
  • 70
  • 99
  • 5
    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 Sep 25 '18 at 13:18
  • 11
    @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 – S.Serpooshan Dec 09 '18 at 08:05
  • 8
    /me hides away, embarassed. – Pure.Krome Dec 09 '18 at 22:57
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
WhileTrueSleep
  • 1,524
  • 1
  • 19
  • 32