Symptom
After adding Azure Artifacts feed to Visual Studio's NuGet package sources, the PowerBuilder IDE fails to restore NuGet packages and throws multiple messages like the following:
<Drive>:\<App path>\ServerAPIs\ServerAPIs.csproj : error NU1301: Unable to load the service index for source https://pkgs.dev.azure.com/<company name>/_packaging/<company name>_Cloud_NuGet/nuget/v3/index.json.
Environment
PowerServer 2022 R3 and later
Cause
After adding an Azure Artifacts feed to Visual Studio's NuGet package sources, it also modifies the user-level NuGet package sources by default (%AppData%\NuGet\NuGet.Config). However, Visual Studio has built-in logic to manage Azure Artifacts authentication.
After generating C# solution for the PowerServer project, to run the Web API application, the project in C# solution needs to restore NuGet packages using .NET SDK. When executing dotnet build command, NuGet fails to connect to the Azure Artifacts feed and raises error NU1301.
Resolution
There are two solutions.
Solution 1)
If you want to keep the Azure Artifacts feed in user-level package sources, meaning not only Visual Studio but also PowerBuilder and other applications can access the Azure Artifacts feed, you can install the Azure Artifacts Credential Provider:
https://github.com/microsoft/artifacts-credprovider?tab=readme-ov-file#nugetexe-or-msbuild
a) Setup
Automatic PowerShell script
To install netcore, run installcredprovider.ps1
Example:
iex "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) }"
Refer to:
https://github.com/microsoft/artifacts-credprovider?tab=readme-ov-file#installation-on-windows
b) Authentication
The first time you perform an operation that requires authentication using dotnet, you should either use the --interactive flag to allow dotnet to prompt you for credentials, or provide them through an environment variable.
If interactive authorization is available, navigate to your project directory and run:
dotnet restore --interactive
Once you've successfully signed in your Azure account and acquired a token, you can run authenticated commands without the --interactive flag for the lifespan of the token, which is saved in the session token cache location.
c) Verify
Run your PowerServer project to verify that the issue is resolved.
Solution 2)
If you only want to disable the Azure Artifacts feed in PowerServer solutions at the solution-level, follow these simplified steps
a) Create a solution-level NuGet configuration file
Create an empty ‘NuGet.Config’ file in the PowerServer C# solution root directory (the same folder as the ‘.sln’ file). Then add a configuration to disable the Azure/private feed package source so only the desired sources remain enabled for this C# solution.
Solution-level NuGet.Config example:
| <?xml version="1.0" encoding="utf-8"?> <configuration> <disabledPackageSources> <add key="{Your Azure Feed Name}" value="true" /> </disabledPackageSources> </configuration> |
Refer to: https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file#disabledpackagesources
b) Verify the new NuGet configuration
Run your PowerServer Project to verify that the issue is resolved.