1
votes

Migrating to my Linux machine for work I have run into a problem with Nuget. Our projects are .net core 3.1 and each has its own nuget.config file which has four package sources in it. The first is the obvious one but the rest are specific for the company.

Whenever I build I get an error stating that I am not authorised:

/usr/share/dotnet/sdk/3.1.301/NuGet.targets(128,5): error : Unable to load the service index for source https://aldinternational.pkgs.visualstudio.com/_packaging/PLASMA/nuget/v3/index.json. [/home/lg/Documents/ALD/repo/CampaignIngestion.OmegaConnector/OmegaConnector.Functions/OmegaConnector.Functions.csproj] /usr/share/dotnet/sdk/3.1.301/NuGet.targets(128,5): error : Response status code does not indicate success: 401 (Unauthorized). [/home/lg/Documents/ALD/repo/CampaignIngestion.OmegaConnector/OmegaConnector.Functions/OmegaConnector.Functions.csproj] 0 Warning(s) 1 Error(s)

but I can get the json output when I put that in a browser. I have run:

mozroots --import --sync --url https://hg.mozilla.org/mozilla-central/raw-file/tip/security‌​/nss/lib/ckfw/builti‌​ns/certdata.txt

as the thread I found it on seemed to having a similar issue but for me no luck.

dotnet --info output

.NET Core SDK (reflecting any global.json):
 Version:   3.1.301
 Commit:    7feb845744

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  18.04
 OS Platform: Linux
 RID:         ubuntu.18.04-x64
 Base Path:   /usr/share/dotnet/sdk/3.1.301/

Host (useful for support):
  Version: 3.1.5
  Commit:  65cd789777

.NET Core SDKs installed:
  2.1.302 [/usr/share/dotnet/sdk]
  2.2.300 [/usr/share/dotnet/sdk]
  3.1.301 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

The build is definitely hitting the correct nuget.config and is not using my local use config. How can I fix this issue?

I have all packages from key="nuget.org" value="https://api.nuget.org/v3/index.json" downloaded as it is the first in the list I think.

1

1 Answers

2
votes

This all came down to adding the correct packageSourceCredentials to the correct nuget.config file. I have

  1. ~/.config/NuGet/nuget.config
  2. ~/.nuget/NuGet/nuget.config
  3. solution level nuget.config file

Don't use #3 for this as that puts user set up at solution level and it is committed. #1 doesn't seem to have any affect when I do "dotnet build" from the project folder. #2 is the file that needs the credentials set up (for me anyway).

Next issue is that we have PAT code access set up on our private repo but non-windows platforms do not support the encryption but just placing a clear text password there is no good either. What I needed to do was:

  1. Go to VSTS log in with my account and generate a PAT code
  2. Create PackageSourceCredentials section in #2 nuget configuration file
  3. for each repo that needs credentials create a section for its name within PackageSourceCredentials section i.e. for

<add key="PLASMA" value="" protocolVersion="3" />

(PLASMA is defined in #3 nuget.config files on our set up)

<PLASMA>
      <add key="Username" value="your username for PAT code" />
      <add key="ClearTextPassword" value="Copied PAT code from vsts" />
</PLASMA>

If you just use password instead of ClearTextPassword it does not seem to work and "Copied PAT code" is the one you copy out of vsts. It does not appear to matter that the package sources I need credentials for are defined in #3 config files and the credentials for them are defined in #2 config file.