NuGet uses invalid feed when adding a new package - xamarin

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

Related

NuGet fails to find package if it's not in Cache

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>

Installing NuGet package with dependencies on multiple sources

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

Team Foundation Build with Private NuGet Feed

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

How do you add a mime type when using ASP.NET vNext?

There's LOADS of information on how to add MIME types into a normal project.
These include configuring IIS, or modifying the web.config.
Both of these options are unavailable to me in vNext with IIS Express.
I had a look at the schema to the project.json file and couldn't find anything in there that would help either.
Can this be done yet? - I want to add a mime type for the .woff2 extension.
If you hosting it on IIS 7 or later then following step will do what you need. This answer I have used Visual Studio 2015 CTP5.
Publish your web application ( ASP.net vnext)
You can publish it to location like C:\MyPublish
Once it get successfully published you will find following location C:\MyPublish\wwwroot. Here You will find web.config.
Now host your site to in IIS ( Make sure that you have used C:\MyPublish\wwwroot as your path)
Now edit web.config over here just like you did for old version to add mime type. ( Following is my edit)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="kpm-package-path" value="..\approot\packages" />
<add key="bootstrapper-version" value="1.0.0-beta2" />
<add key="kre-package-path" value="..\approot\packages" />
<add key="kre-version" value="1.0.0-beta2" />
<add key="kre-clr" value="CLR" />
<add key="kre-app-base" value="..\approot\src\WebApplication5" />
</appSettings>
<system.webServer>
<staticContent>
<remove fileExtension=".woff" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
</staticContent>
</system.webServer>
</configuration>
Note: As per my thinking In old version it is fix that it is always windows environment so we have direct web.config file in project and we edit that but now we have to follow different process to register as in future we can host completly on linux env as well.
Update : There is another way to do that as well. If you are using Microsoft.AspNet.StaticFiles package then you will have extension.
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles();
}
This will indirectly use https://github.com/aspnet/StaticFiles/blob/dev/src/Microsoft.AspNet.StaticFiles/FileExtensionContentTypeProvider.cs. Here you can see all mapping.
Update 2: (Add New Mime Type)
public void Configure(IApplicationBuilder app)
{
StaticFileOptions option = new StaticFileOptions();
FileExtensionContentTypeProvider contentTypeProvider = (FileExtensionContentTypeProvider)option.ContentTypeProvider;
contentTypeProvider.Mappings.Add("<<yourextention>>","<<mimetype>>");
app.UseStaticFiles(option);
}
Until this is released, you can also edit applicationhost.config which I found in D:\Documents\IISExpress\config (yours might be on your C drive [Documents]).
I added:
<mimeMap fileExtension=".woff2" mimeType="font/x-woff2" />
Inside <staticContent>.

NuGet and VS2013 ignoring packageSourceCredentials in nuget.config

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.

Resources