My job has a private NuGet repo. I'm able to install packages from it and from nuget.org. I'm running into problems when there's a package stored on the private repo that has a dependency on a package hosted on nuget.org.
For instance, my private repo hosts a package, P1. P1 has a dependency on P2 which is hosted on nuget.org. If do an "install-package P1" with my private repo set as the source i'll get an error saying it couldn't find the dependency P2. This makes sense since it's looking for P2 in the private repo but it's hosted on nuget.org. So far the workaround has been installing P2 from nuget.org then installing P1 from the private repo. While this technically works it's tedious and going to make selling NuGet to the rest of the team difficult.
Is there anyway I can run install-package with multiple sources? I've tried passing a list into the -Source parameter but so far have gotten
The NuGet.config is being managed by visual studio so any changes I make to it are being wiped out every time a run a nuget command in Visual Studio. I tried adding an additional nuget.config file at the solution level but as far as I can tell it was being ignored. I've tried several visitations of the install=package command but they generally look something like this:
Install-Package P1 -Source https://api.nuget.org/v3/index.json,http://privatefeed.com
For reference here is the NuGet.config file but changing it seems futile.
<?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://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="Private Nuget" value="http://privatefeed.com" />
</packageSources>
<disabledPackageSources>
<add key="Microsoft and .NET" value="true" />
</disabledPackageSources>
<activePackageSource>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</activePackageSource>
</configuration>
Using NuGet.exe, you can repeat the -Source option to specify multiple package sources.
Example:
nuget install P1 -Source https://api.nuget.org/v3/index.json -Source http://privatefeed.com
It appears that it's impossible to specify multiple sources using the Package Manage Console (PowerShell). However, if no -Source is specified then a NuGet.Config file is used. The config file can have multiple package sources and the file itself can be shared with a team.
<?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 Nuget" value="http://privatefeed.com" />
</packageSources>
</configuration>
Save as NuGet.Config in the same directory as your solution and add it to version control.
Note that you might have to reload visual studio for the config changes to take effect.
Now you can install packages without configuring -Source.
Example:
Install-Package P1
Related
I've been using both a public and a private feed for NuGet and I've added them in a Nuget.Config file in my project's root:
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="ligetFeed" value="http://graymini.local:9011/api/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
Running nuget restore works fine, and restores packages from both nuget.org and my private feed, but while trying to add a new nuget from nuget.org, it fails because it uses the private feed instead of nuget.org. I've been trying to add it both from Visual Studio (Mac) and command line, via nuget install <package> but the same thing happens.
The output looks like this:
Feeds used:
https://api.nuget.org/v3/index.json
http://privatefeed.local:9011/api/v3/index.json
Installing package 'Polly' to '/Users/user/Documents/MyProject'.
CACHE https://api.nuget.org/v3/registration4-gz-semver2/polly/index.json
GET http://privatefeed.local:9011/api/v3/registration/polly/index.json
An error was encountered when fetching 'GET http://privatefeed.local:9011/api/v3/registration/polly/index.json'. The request will now be retried.
mono-io-layer-error (-1)
GET http://privatefeed.local:9011/api/v3/registration/polly/index.json
An error was encountered when fetching 'GET http://privatefeed.local:9011/api/v3/registration/polly/index.json'. The request will now be retried.
mono-io-layer-error (-1)
GET http://privatefeed.local:9011/api/v3/registration/polly/index.json
An error occurred while retrieving package metadata for 'Polly' from source 'ligetFeed'.
mono-io-layer-error (-1)
Notice it tries to use GET http://privatefeed.local:9011/api/v3/registration/polly/index.json instead of api.nuget.org
Are there any extra steps needed? How does NuGet decide which feed to use?
N.B. I've managed to add the package just fine by removing the private feed entry from Nuget.Config, adding the package, then re-adding the feed and restoring, but this doesn't seem right on the long term.
Unfortunately , there is no way to set the an OPTIONAL priority for feeds to solve that problem .I hope can do that as follow :
<packageSources>
<!-- Internal package source comes before NuGet.org proxy -->
<add key="my_private_feed" value="http://internal-server:8081/repository/private_feed1/" priority="1" />
<add key="cache_nugetorg" value="https://www.nuget.org/api/v2/" priority="2" />
</packageSources>
However , it can not support . From this issue link , I know that :
This is by design, sources are unordered and they are searched by order of the quickest response rather than by order of how they show up in file.
By the way , there is an unperfect way to set nuget.org disable by using activePackageSource and disabledPackageSources .
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="Chuck Norris Feed" value="https://www.myget.org/F/chucknorris" />
</packageSources>
<disabledPackageSources>
<add key="nuget.org" value="true" />
</disabledPackageSources>
<activePackageSource>
<add key="Chuck Norris Feed" value="https://www.myget.org/F/chucknorris" />
</activePackageSource>
</configuration>
However , this way also can't realize it. I also find this issue link , Priority methods have been proposed as suggestions .
Finally , I will look forward to such a method in the future.
Turns out it's a problem with mono and mDNS (.local). I've been using Mac OS for the Nuget Feed with LiGet and as you may know, you can access any other Mac on the network with either the IP or name.local, as I did with graymini.local
After replacing the feed in NuGet.Config from
<add key="ligetFeed" value="http://graymini.local:9011/api/v3/index.json" protocolVersion="3" />
to
<add key="ligetFeed" value="http://22.33.444.555:9011/api/v3/index.json" protocolVersion="3" />
Everything seems to work fine. Trying to obtain the new package from the private feed will return NotFound instead of erroring with mono-io-layer-error and it will continue just fine fetching it from nuget.org instead.
GET https://api.nuget.org/v3/registration4-gz-semver2/polly/index.json
GET http://22.33.444.555:9011/api/v3/registration/polly/index.json
NOTFOUND http://22.33.444.555:9011/api/v3/registration/polly/index.json
OK https://api.nuget.org/v3/registration4-gz-semver2/polly/index.json
I've recently uninstalled Service Fabric and its SDK from my machine. However, it has left behind a machine-wide package source:
Microsoft Azure Service Fabric SDK
C:\Program Files\Microsoft SDKs\Service Fabric\packages
This folder no longer exists. It is causing my build to fail. Unticking this option as an available source doesn't seem to persist between sessions.
How can I permanently remove this package source?
UPDATE
In the Visual Studio options, delete is not available for this package source. I can untick it, but that doesn't seem to be persistent.
My NuGet.config doesn't reference it either. I can't find another NuGet.config on my computer.
%AppData%\NuGet\NuGet.config
<?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="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
</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>
I found that deleting this file (as an Administrator) solved the problem. It must have been missed by the Service Fabric uninstaller.
C:\Program Files (x86)\NuGet\Config\ServiceFabricSDK.config
just delete unwanted .config files in C:\Program Files (x86)\NuGet\Config
I had this same issue on an Azure Devops build machine, which was causing a build failure when it would build locally and on other build machines. Found this file here: C:\Program Files (x86)\NuGet\Config\nuget.config which contained the offending packages.
deleted the nuget.config file at that location and worked like a charm. Hope this helps someone.
How can I permanently remove this package source?
When we create Service Fabric application with Visual Studio, we always receive following message in the output window:
An error occurred attempting to configure NuGet to reference the
Service Fabric SDK package location as a package source. To fix this,
you can manually add a NuGet package source in the Options window and
setting it to the following path: C:\Program Files\Microsoft
SDKs\Service Fabric\packages.
You may configure nuget setting as suggestion.
So, to permanently remove this package source, you can open the visual Studio Tools->NuGet Package Manager->Package Manager settings->Package Source:
Select that nuget package source and delete it. Or you can open the configuration file nuget.config directly from path C:\Users\<UserName>\AppData\Roaming\NuGet\nuget.config and delete it:
<?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="Test" value="C:\Program Files\Microsoft SDKs\Service Fabric\packages" />
</packageSources>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
...
</configuration>
Move the package source <add key="Test" value="C:\Program Files\Microsoft SDKs\Service Fabric\packages" />.
Hope this helps.
I have an internal feed setup for NuGet. When I try to build one of my projects (via a TFS build server), I get an error that NuGet cannot find version xxx of package yyy.
I go to the NuGet package folder on the server and the correct package/version is there. However, the package/version does not exist in the NuGet cache folder:
C:\Users[user account]\AppData\Local\NuGet\Cache
If I copy the correct package/version to this cache folder, then the build succeeds.
Any ideas?
Possible duplicate with NuGet fails to find existing package . If there are some service issues related to search and package restore functionality. It is possible cause of your package restore failure.
If there is a cached version of this package, NuGet will access there and the restore will be working fine.
The solution is updating your nugget to the latest version (At least 3.4+) You can also refer a similar issue in GitHub: Package restore intermittently fails with "Unable to find version 'x' of package 'y'"
Check Nuget.config in your Project. It should have the path to the Source that is your NuGet package folder on the server should be present in the nuget.config file.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageRestore>
<!-- Allow NuGet to download missing packages -->
<add key="enabled" value="True" />
<!-- Automatically check for missing packages during build in Visual Studio -->
<add key="automatic" value="True" />
</packageRestore>
<activePackageSource>
<!-- this tells that all of them are active -->
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<packageSources>
<add key="PrivatePackages" value="\\TestPath\nuget" />
</packageSources>
</configuration>
How can I configure Team Foundation Build to use a private NuGet feed I have setup with NuGet.Server?
Locally I can add a source with:
nuget.exe sources add -Name "Feed Name" -Source "https://feed.url/nuget/"
How can I achieve this with Team Foundation Build?
You need a NuGet.config file within the solution folder.
Ensure both package sources are added to your NuGet.config file. Also ensure both sources are 'active'.
<configuration>
<packageSources>
<add key="nuget.org"
value="https://www.nuget.org/api/v2/" />
<add key="example.com"
value="http://example.com/feed/nuget/" />
</packageSources>
<activePackageSource>
<add key="All"
value="(Aggregate source)" />
</activePackageSource>
</configuration>
See NuGet configuration file documentation.
Another option that is now available if you use Team Foundation Server is the private hostws NuGet feed they are now trialling.
For more information see this post: http://blogs.msdn.com/b/visualstudioalm/archive/2015/08/27/announcing-package-management-for-vso-tfs.aspx
I have a private nuget server which I am trying to pull packages from (eventually Azure build agent but I am trying this locally first).
I am using the 2.7 NuGet meaning I do not need .NuGet folder (along with .exe and .targets). I have a nuget.config in my solution directory.
I know the nuget.config is being picked up, as it locates my remote repository but the credentials supplied in the config are not used.
Here is my config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<packageSources>
<add key="https://www.nuget.org/api/v2/" value="https://www.nuget.org/api/v2/" />
<add key="myrepo" value="http://myrepo:81/nuget/myfeed" />
</packageSources>
<disabledPackageSources />
<packageSourceCredentials>
<myrepo>
<add key="Username" value="user" />
<add key="ClearTextPassword" value="pass" />
</myrepo>
</packageSourceCredentials>
</configuration>
What would cause nuget to ignore these credentials? I have checked with Fiddler and no credentials are being sent, and the server responds with a 401 (correctly):
Error 1 NuGet Package restore failed for project MyProject: The remote server returned an error: (401) Unauthorized.. 0 0
Use the 'Manage NuGet Packages' dialog !
Do not rely on building/rebuilding in Visual Studio expecting that it will restore the missing packages. Open the 'Manage NuGet Packages' for a project (right click on a failing project and choose the option) and you will see a message "Some packages are missing for this project..." with a 'Restore' button. Restoring using that button will resolve these authentication issues.