rgorr
rgorr

Reputation: 380

Nuget package restore using wrong source and failing in Visual Studio for Mac

I recently transferred a Xamarin project to a new MacBook in order to get everything up to date to the latest iOS version. I am using Visual Studio for Mac 2022.

This project uses Grial UI(version 3) and Telerik for Xamarin Forms which require configuring custom Nuget sources.

I have ran into two problems:

  1. The sources tell me I have "Invalid Credentials" when adding them even though they are correct and I can browse the packages when selecting the source.
  2. When attempting to restore the packages, it uses Nuget.org instead of the proper source. Here is one error it gets:

Unable to find package UXDivers.Grial. No packages exist with this id in source(s): nuget.org

It is supposed to be using the custom Grial Nuget source that I have added, not nuget.org.

Number 1. might be a non-issue but maybe indicates something else is configured wrong, but 2 makes me unable to build the project at all because these references aren't used.

I have also tried to update the packages using Nuget package manager which detects the current version and available versions successfully and it fails for the same reason(using the wrong source when doing the actual update).

Any suggestions on how to fix this? My Nuget sources are configured in the exact same way on my older(mid-2015) Mac and it is working with VS for Mac 2019.

Upvotes: 1

Views: 1332

Answers (2)

shalin
shalin

Reputation: 452

My final steps are as this

  1. dotnet nuget locals --clear all (did this multiple times)

  2. dotnet nuget locals --list all (list all nuget locations, go to those and delete)

  3. dotnet restore the project (even platform projs)

After all, the package restore still goes to the older Telerik server (You must check the package console before, which I did, but not enough)

Check this - NuGet Config files used:

/Users/"YOUR_USERNAME"/.config/NuGet/NuGet.Config



and you will see "Feeds used:" In there, you will see the wrong nuget source, 

not in "/Users/"YOUR_USERNAME"/.nuget/NuGet



REMOVE unwanted nuget sources from " /Users/"YOUR_USERNAME"/.config/NuGet/NuGet.Config"



Project builds !!!

For further details, check this in the Microsoft

Upvotes: 0

grabnerM
grabnerM

Reputation: 19

I had the same problem. On my MacBookAir everything worked fine (bought in november 2022), now i got a MacBookPro from work. I installed everything but when it came to running my Xamarin project, restoring the project always failed.

In the package console output i found that the only used feeds were

https://api.nuget.org/v3/index.json

Randomly but luckily i found a link to the microsoft documentation. (https://learn.microsoft.com/en-us/nuget/consume-packages/configuring-nuget-behavior). I checked my NuGet.config file on my MacBookPro and MacBookAir. And there was the error. I don´t know why but when i added my grial-resource to the nuget sources, it did not update my NuGet.config file.

So my NuGet.config file looked like that

<?xml version="1.0" encoding="utf-8"?>
<configuration>
   <packageSources>
      <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
   </packageSources>
</configuration>

While on my MacBookAir it looked like that

<?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="grial" value="http://nuget.uxdivers.com/grial" />
  </packageSources>
  <packageSourceCredentials>
    <grial>
        <add key="Username" value="yourUsername" />
        <add key="ClearTextPassword" value="yourPassword" />
    </grial>
  </packageSourceCredentials>
</configuration>  

So to fix the problem on my MacBookPro i added the grial source to the file, saved it and restarted VSforMac. Now i can build my project on both my MacBooks.

Upvotes: 1

Related Questions