[c#] Where is NuGet.Config file located in Visual Studio project?

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>

The answer is


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://docs.microsoft.com/en-us/nuget/schema/nuget-config-file


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.


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.


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>

I have created an answer for this post that might help: https://stackoverflow.com/a/63816822/2399164

Summary:

I am a little late to the game but I believe I found a simple solution to this problem...

  1. Create a "NuGet.Config" file in the same directory as your .sln
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="{{CUSTOM NAME}}" value="{{CUSTOM SOURCE}}" />
  </packageSources>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <bindingRedirects>
    <add key="skip" value="False" />
  </bindingRedirects>
  <packageManagement>
    <add key="format" value="0" />
    <add key="disabled" value="False" />
  </packageManagement>
</configuration>
  1. That is it! Create your "Dockerfile" here as well

  2. Run docker build with your Dockerfile and all will get resolved


Questions with c# tag:

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array How can I add raw data body to an axios request? Couldn't process file resx due to its being in the Internet or Restricted zone or having the mark of the web on the file Convert string to boolean in C# Entity Framework Core: A second operation started on this context before a previous operation completed ASP.NET Core - Swashbuckle not creating swagger.json file Is ConfigurationManager.AppSettings available in .NET Core 2.0? No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization Getting value from appsettings.json in .net core .net Core 2.0 - Package was restored using .NetFramework 4.6.1 instead of target framework .netCore 2.0. The package may not be fully compatible Automatically set appsettings.json for dev and release environments in asp.net core? How to use log4net in Asp.net core 2.0 Get ConnectionString from appsettings.json instead of being hardcoded in .NET Core 2.0 App Unable to create migrations after upgrading to ASP.NET Core 2.0 Update .NET web service to use TLS 1.2 Using app.config in .Net Core How to send json data in POST request using C# ASP.NET Core form POST results in a HTTP 415 Unsupported Media Type response How to enable CORS in ASP.net Core WebAPI VS 2017 Metadata file '.dll could not be found How to set combobox default value? How to get root directory of project in asp.net core. Directory.GetCurrentDirectory() doesn't seem to work correctly on a mac ALTER TABLE DROP COLUMN failed because one or more objects access this column Error: the entity type requires a primary key How to POST using HTTPclient content type = application/x-www-form-urlencoded CORS: credentials mode is 'include' Visual Studio 2017: Display method references Where is NuGet.Config file located in Visual Studio project? Unity Scripts edited in Visual studio don't provide autocomplete How to create roles in ASP.NET Core and assign them to users? Return file in ASP.Net Core Web API ASP.NET Core return JSON with status code auto create database in Entity Framework Core Class Diagrams in VS 2017 How to read/write files in .Net Core? How to read values from the querystring with ASP.NET Core? how to set ASPNETCORE_ENVIRONMENT to be considered for publishing an asp.net core application? ASP.NET Core Get Json Array using IConfiguration Entity Framework Core add unique constraint code-first No templates in Visual Studio 2017 ps1 cannot be loaded because running scripts is disabled on this system

Questions with visual-studio tag:

VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio? How to download Visual Studio Community Edition 2015 (not 2017) Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error How to fix the error "Windows SDK version 8.1" was not found? Visual Studio Code pylint: Unable to import 'protorpc' Open the terminal in visual studio? Is Visual Studio Community a 30 day trial? How can I run NUnit tests in Visual Studio 2017? Visual Studio 2017: Display method references Visual Studio 2017 errors on standard headers Where is NuGet.Config file located in Visual Studio project? Visual Studio 2017 error: Unable to start program, An operation is not legal in the current state Visual Studio 2017 - Git failed with a fatal error Unity Scripts edited in Visual studio don't provide autocomplete Equivalent to AssemblyInfo in dotnet core/csproj How to enable C++17 compiling in Visual Studio? Nuget connection attempt failed "Unable to load the service index for source" Change language of Visual Studio 2017 RC Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies Visual Studio Code how to resolve merge conflicts with git? Getting "project" nuget configuration is invalid error "Object doesn't support property or method 'find'" in IE localhost refused to connect Error in visual studio Why is the Visual Studio 2015/2017/2019 Test Runner not discovering my xUnit v2 tests Build error, This project references NuGet Visual Studio Code always asking for git credentials Stuck while installing Visual Studio 2015 (Update for Microsoft Windows (KB2999226)) Visual Studio error "Object reference not set to an instance of an object" after install of ASP.NET and Web Tools 2015 C# - How to convert string to char? Multiple Errors Installing Visual Studio 2015 Community Edition Why Visual Studio 2015 can't run exe file (ucrtbased.dll)? Where can I read the Console output in Visual Studio 2015 Go To Definition: "Cannot navigate to the symbol under the caret." CMake error at CMakeLists.txt:30 (project): No CMAKE_C_COMPILER could be found How to remove error about glyphicons-halflings-regular.woff2 not found NuGet Packages are missing Visual Studio Community 2015 expiration date How to solve ERR_CONNECTION_REFUSED when trying to connect to localhost running IISExpress - Error 502 (Cannot debug from Visual Studio)? Where is the visual studio HTML Designer? error C4996: 'scanf': This function or variable may be unsafe in c programming What are the differences between Visual Studio Code and Visual Studio? Is Xamarin free in Visual Studio 2015? What's the difference between Visual Studio Community and other, paid versions? Visual Studio 2015 installer hangs during install? How to use class from other files in C# with visual studio? 'cannot find or open the pdb file' Visual Studio C++ 2013 How to build x86 and/or x64 on Windows from command line with CMAKE? Python Pip install Error: Unable to find vcvarsall.bat. Tried all solutions How to enable C# 6.0 feature in Visual Studio 2013?

Questions with .net-core tag:

dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Assets file project.assets.json not found. Run a NuGet package restore Is ConfigurationManager.AppSettings available in .NET Core 2.0? How to update record using Entity Framework Core? Using app.config in .Net Core EF Core add-migration Build Failed Build .NET Core console application to output an EXE What is the difference between .NET Core and .NET Standard Class Library project types? Where is NuGet.Config file located in Visual Studio project? The default XML namespace of the project must be the MSBuild XML namespace Return file in ASP.Net Core Web API auto create database in Entity Framework Core Equivalent to AssemblyInfo in dotnet core/csproj How to read/write files in .Net Core? How to read values from the querystring with ASP.NET Core? Is it possible to make desktop GUI application in .NET Core? How to run .NET Core console app from the command line How to change the port number for Asp.Net core app? Homebrew refusing to link OpenSSL How to get HttpContext.Current in ASP.NET Core? How to determine if .NET Core is installed How to unapply a migration in ASP.NET Core with EF Core AddTransient, AddScoped and AddSingleton Services Differences ASP.NET Core configuration for .NET Core console application What's the difference between .NET Core, .NET Framework, and Xamarin? Send HTTP POST message in ASP.NET Core using HttpClient PostAsJsonAsync .NET Core vs Mono How to use SqlClient in ASP.NET Core? How to read AppSettings values from a .json file in ASP.NET Core What is ".NET Core"? How to set javascript variables using MVC4 with Razor How do I show a "Loading . . . please wait" message in Winforms for a long loading form?

Questions with visual-studio-2017 tag:

Assets file project.assets.json not found. Run a NuGet package restore How to remove an unpushed outgoing commit in Visual Studio? The current .NET SDK does not support targeting .NET Standard 2.0 error in Visual Studio 2017 update 15.3 Create Setup/MSI installer in Visual Studio 2017 VS 2017 Metadata file '.dll could not be found Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error Visual Studio 2017 does not have Business Intelligence Integration Services/Projects How can I run NUnit tests in Visual Studio 2017? How to integrate SAP Crystal Reports in Visual Studio 2017 Unit Tests not discovered in Visual Studio 2017 Visual Studio 2017: Display method references Visual Studio 2017 errors on standard headers Visual Studio 2017 - Could not load file or assembly 'System.Runtime, Version=4.1.0.0' or one of its dependencies Where is NuGet.Config file located in Visual Studio project? How can I install the VS2017 version of msbuild on a build server without installing the IDE? Visual Studio 2017 error: Unable to start program, An operation is not legal in the current state Visual Studio 2017 - Git failed with a fatal error How to download Visual Studio 2017 Community Edition for offline installation? Class Diagrams in VS 2017 Equivalent to AssemblyInfo in dotnet core/csproj No templates in Visual Studio 2017 Reportviewer tool missing in visual studio 2017 RC Change language of Visual Studio 2017 RC Predefined type 'System.ValueTuple´2´ is not defined or imported Visual Studio 2015 or 2017 does not discover unit tests Force uninstall of Visual Studio How can I fix the Microsoft Visual Studio error: "package did not load correctly"?

Questions with visual-studio-2019 tag:

How can I run NUnit tests in Visual Studio 2017? Where is NuGet.Config file located in Visual Studio project? How can I install the VS2017 version of msbuild on a build server without installing the IDE? Force uninstall of Visual Studio