Home: nuget.org not added to %AppData%\NuGet\nuget.config if file already contains a packageSource

Created on 23 Jun 2017  路  7Comments  路  Source: NuGet/Home

I'm seeing some scenarios where nuget.org is not added to %AppData%\NuGet\nuget.config if it already contains a packageSource. Here's an example:

  1. Manually create %AppData%\NuGet\nuget.config with the following content:
<?xml version="1.0"?>
<configuration>
  <packageSources>
  </packageSources>
</configuration>
  1. Install Visual Studio 15.3, but do not open it after installing.
  2. Install .NET Core CLI 2.0.0-preview2. This adds CliFallbackFolder as a package source:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="CliFallbackFolder" value="C:\Users\Administrator\.dotnet\NuGetFallbackFolder" />
  </packageSources>
</configuration> 
  1. Open VS.
  2. Tools -> Options -> NuGet Package Manager -> Package Sources
  3. nuget.org is not listed as a package source, so any project depending on nuget.org will fail

nuget.org is added as a package source if any of the following steps are changed:

  • %AppData%\NuGet\nuget.config does not exist when the .NET Core CLI is installed

    • After installing the .NET Core CLI, the file will contain both nuget.org and CliFallbackFolder package soruces

  • Before installing the .NET Core CLI, open VS and navigate to Tools -> Options -> NuGet Package Manager -> Package Sources.

    • This step adds nuget.org as a package source.

    • After installing the .NET Core CLI, the file will contain both nuget.org and CliFallbackFolder package sources

While step 1 above (creating %AppData%\NuGet\nuget.config with no package sources) may seem artificial, I've found two typical workflows which create the file in this state:

  • On Windows Server 2016, enable Windows Server Containers (https://docs.microsoft.com/en-us/virtualization/windowscontainers/quick-start/quick-start-windows-server)

    • The first step in this doc is to run Install-Module -Name DockerMsftProvider -Repository PSGallery -Force from an elevated powershell, which creates the nuget.config with no package sources.

  • Install Chocolatey (https://chocolatey.org/install), then install a package (e.g. choco install -y nuget.commandline).

I suspect the root cause may be that these workflows are using an older version of NuGet.

Settings Bug

Most helpful comment

For anyone looking for the error error NU1101: Unable to find package XXXXXX. No packages exist with this id in source(s): CliFallbackFolder after installing .NET Core Preview 2: You need to manually add the nuget feed to %AppData%\NuGet\nuget.config.

In my case I ended up with:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="CliFallbackFolder" value="C:\Users\Administrator\.dotnet\NuGetFallbackFolder" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration> 

All 7 comments

For anyone looking for the error error NU1101: Unable to find package XXXXXX. No packages exist with this id in source(s): CliFallbackFolder after installing .NET Core Preview 2: You need to manually add the nuget feed to %AppData%\NuGet\nuget.config.

In my case I ended up with:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="CliFallbackFolder" value="C:\Users\Administrator\.dotnet\NuGetFallbackFolder" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration> 

@rrelyea @zhili1208 Reassigning this bug as per the discussion during the sprint planning meeting.

@mikeharder how common is this scenario? Creating the nuget.config with no package sources is a bug which was fixed in 3.4, I don't think nuget should take a fix (basically a hack) to fix old version of nuget.

nuget have a hack which is for empty nuget.config, if there is no package source in nuget.config, and nuget never add nuget.org to nuget.config (tracking by a trk file), then add nuget.org.

If there is any source in nuget.config, nuget will do nothing.

So in this scenario, there is a source(cli source) in nuget.config, that's why the above hack is not working here.

adding nuget.org to nuget.config if there is any source in nuget.config means a breaking change and bringing back old behavior.

I think we should not fix this OR CLI can take a similar hack like nuget did for empty nuget.config

I don't know how common this is for customers. I hit it twice without trying as described above. I think the CLI may have stopped adding CliFallbackFolder to nuget.config. If so, this issue may be much less common.

If CLI stopped adding CLIFallbackFolder to nuget.config, the nuget hack above will cover the empty nuget.config case. Then this will be an edge case. Close it as won't fix for now. Feel free to reopen it if there are more hits.

I have same issue. I am using a private Nuget Server and from that server a private package in my visual studio 17 asp.net core project. When 谋 prepare and launch dockerfile with build command it turns:

/app/My.Asp.Net.Core.csproj : error NU1101: Unable to find package My.Private.Package. No packages exist with this id in source(s): nuget.org
Generating MSBuild file /app/obj/My.Asp.Net.Core.csproj.nuget.g.props.
Generating MSBuild file /app/obj/My.Asp.Net.Core.csproj.nuget.g.targets.
Restore failed in 17.74 sec for /app/My.Asp.Net.Core.csproj.
The command '/bin/sh -c dotnet restore' returned a non-zero code: 1

My NuGet.Config file is:

?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="Private" value="http://MyPrivateServer.net/nuget" />
  </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="True" />
  </packageManagement>
  <apikeys>
    <add key="https://www.nuget.org" value="Some_Long_Value" />
  <add key="http://MyPrivateServer.net/nuget" value="My_Api_Key_To_Server"/>
  </apikeys>
  <disabledPackageSources />
</configuration>

MyDockerfile is:

FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM microsoft/aspnetcore:2.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "My.Asp.Net.Core.dll"]

The error pops up at RUN dotnet restore command. Is there any solution for that?

I am on a MAC using the same dotnet restore and I get

/app/CrimeApi.csproj : error NU1101: Unable to find package CoreModels. No packages exist with this id in source(s): nuget.org
/app/CrimeApi.csproj : error NU1101: Unable to find package CrimeLibrary. No packages exist with this id in source(s): nuget.org
/app/CrimeApi.csproj : error NU1101: Unable to find package GeoProcessing. No packages exist with this id in source(s): nuget.org

Naturally these errors are specific to my application but the general problem remains that the local NuGet source is not recognized. There isn't a ~/Library/NuGet folder (I am told that ~/Library is the MAC equivalent to %APPDATA%.). Where on a MAC should the "fallback" folder be? In ~/.dotnet there also isn't a folder for NuGet. There is also not a Tools -> Options menu option in the VS Community for MAC.

Thank you.

Was this page helpful?
0 / 5 - 0 ratings