How I dealt with a strange problem with PSRepositories and dotnet NuGet sources

Background

We regularly re-build our Azure DevOps private agents using Packer and Lability, as I have posted about before.

Since the latest re-build, we have seen all sorts of problems. All related to pulling packages and tools from NuGet based repositories. Problems we have never seen with any previous generation of our agents.

The Issue

The issue turned out to be related to registering a private PowerShell repository.

1$RegisterSplat = @{
2Name = 'PrivateRepo'
3SourceLocation = 'https://psgallery.mydomain.co.uk/nuget/PowerShell'
4PublishLocation = 'https://psgallery.mydomain.co.uk/nuget/PowerShell'
5InstallationPolicy = 'Trusted'
6}
7
8Register-PSRepository @RegisterSplat

Running this command caused the default dotnet NuGet repository to be unregistered i.e. the command dotnet nuget list source was expected to return

1Registered Sources:
2  1.  PrivateRepo
3      https://psgallery.mydomain.co.uk/nuget/Nuget
4  2.  nuget.org [Enabled]
5      https://www.nuget.org/api/v2/
6  3.  Microsoft Visual Studio Offline Packages [Enabled]
7      C:Program Files (x86)Microsoft SDKsNuGetPackages 

But it returned

1Registered Sources:
2  1.  PrivateRepo
3      https://psgallery.mydomain.co.uk/nuget/Nuget
4  2.  Microsoft Visual Studio Offline Packages [Enabled]
5      C:Program Files (x86)Microsoft SDKsNuGetPackages

The Workaround

You can't call this a solution, as I cannot see why it is really needed, but the following command does fix the problem

1 dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org