Mason G. Zhwiti
Mason G. Zhwiti

Reputation: 6540

Visual Studio 2013 ignores nuget.config

I have a Visual Studio 2013 project that uses Nuget. I have a packages.config file in the root directory of the solution, defining the Nuget packages we want installed. I also have a nuget.config file in the root directory of the solution, defining packageSources, as well as some packageSourceCredentials. One of the package sources is a private repo for our company.

If I open a command prompt in that root directory of the solution, and type nuget restore it works fine, and is able to hit our private repos to pull in some of the custom packages we use.

But if I open the solution in Visual Studio 2013, and build it, it fails when trying to download our custom packages, because apparantly it is ignoring our nuget.config file, and thus does not know about our private nuget repo.

I could go into Tools > Options and add our private repo, but we're trying to do everything within the solution itself, so that it builds out-of-the-box with no custom configuration needed.

Why is nuget.config being ignored by VS 2013?

Upvotes: 21

Views: 6681

Answers (4)

Mike Dimmick
Mike Dimmick

Reputation: 9802

I found that if you have a multi-project solution, with the projects all in folders under the solution folder, putting the NuGet.config in a project folder doesn't work. It doesn't pick up the private package source. It does work if you put a NuGet.config in the solution folder.

That is, this doesn't work:

  • Solution
    • ProjectA
      • ProjectA.csproj
    • ProjectB
      • ProjectB.csproj
      • NuGet.config

while this does work:

  • Solution
    • ProjectA
      • ProjectA.csproj
    • ProjectB
      • ProjectB.csproj
    • NuGet.config

I also found that the disableSourceControlIntegration option does not work when specified in \NuGet.config. It only works when in .nuget\NuGet.config. So I have two config files for my solution, one at the root which holds the package source configuration, and one in the .nuget folder with the disableSourceControlIntegration option.

Tested with Visual Studio 2012 Update 5 and NuGet Package Manager extension 2.8.5.

Upvotes: 1

Joseph Devlin
Joseph Devlin

Reputation: 1800

I created a new project with the following directory structure.

-ConsoleApplication1
    -ConsoleApplication1
    -ConsoleApplication1.sln
    -nuget.config

Prior to adding the nuget.config I could not see any of my private repos when using the Manage Nuget Packages For Solution feature. When I added the nuget.config I was able to see my new repos in the dialog window. I am also able to restore my packages using nuget restore and from a build within VS 2013.

My nuget.config looks like this

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <packageRestore>
        <add key="enabled" value="True" />
        <add key="automatic" value="True" />
    </packageRestore>
    <packageSources>
        <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
        <add key="MyRepo" value="http://XX.XX.XXX.XX:81/host/repo" />
    </packageSources>
    <activePackageSource>
        <add key="All" value="(Aggregate source)" />
    </activePackageSource>
</configuration>

Based on your described issue the only thing I can think is that you may have previously attempted to disable Nuget Package Restore from your project prior to using the up to date method of restoring packages. If you don't carpet bomb package restore from every project simultaneously some logic could be left over that may interfere with the new method. For example, if you deleted the .nuget folder from your solution the nuget.config file could still be in there causing conflicts.

Upvotes: 3

Dave Mackersie
Dave Mackersie

Reputation: 1061

Restart Visual Studio after editing NuGet.config!

I've noticed that VS2012 doesn't pick up on changes to NuGet.config until after I restart it.

Upvotes: 18

Frano Hartman
Frano Hartman

Reputation: 36

Is under your solution Web Site project or Web Application project? I think that web site project ignore nuget.config file.

Upvotes: 0

Related Questions