I need to run an Asp.Net Core application in WSL (Ubuntu 22.04), I'm trying to execute command:
dotnet restore
to restore my nuget packages from default nuget.org and from my private feed on Azure Devops Server 2019. I set the feed in NuGet.config file with credentials and API key like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="Nuget" value="https://api.nuget.org/v3/index.json"/>
<add key="MyFeed" value="https://devops.myfeed.com/tfs/company/_packaging/CompanyPackages/nuget/v3/index.json"/>
</packageSources>
<packageSourceCredentials>
<MyFeed>
<add key="Username" value="DOMAIN\User"/>
<add key="ClearTextPassword" value="PATforPackages"/>
</MyFeed>
</packageSourceCredentials>
</configuration>
But i always get an 401 Unauthorized error. Has anyone had the same problem? How can I solve it? Thanks
UPDATE This is the log stack trace:
1>/usr/lib/dotnet/sdk/8.0.107/NuGet.targets(156,5): error : Unable to load the service index for source https://devops.myfeed.com/tfs/company/_packaging/CompanyPackages/nuget/v3/index.json. ......... /usr/lib/dotnet/sdk/8.0.107/NuGet.targets(156,5): error :
Response status code does not indicate success: 401 (Unauthorized). [/mnt/c/Users/..../MyProject.proj.csproj] Assembly loaded during TaskRun (NuGet.Build.Tasks.RestoreTask): System.Diagnostics.StackTrace, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a (location: /usr/lib/dotnet/shared/Microsoft.NETCore.App/8.0.7/System.Diagnostics.StackTrace.dll, MVID: 7d4e9037-cc6f-43b1-8255-6608ac20f6b1, AppDomain: [Default]) NuGet.Protocol.Core.Types.FatalProtocolException: Unable to load the service index for source https://devops.myfeed.com/tfs/company/_packaging/CompanyPackages/nuget/v3/index.json. ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized). at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() at NuGet.Protocol.HttpSource.<>c__DisplayClass15_01.<<GetAsync>b__0>d.MoveNext() --- End of stack trace from previous location --- at NuGet.Common.ConcurrencyUtilities.ExecuteWithFileLockedAsync[T](String filePath, Func
2 action, CancellationToken token) at NuGet.Common.ConcurrencyUtilities.ExecuteWithFileLockedAsync[T](String filePath, Func2 action, CancellationToken token) at NuGet.Protocol.HttpSource.GetAsync[T](HttpSourceCachedRequest request, Func
2 processAsync, ILogger log, CancellationToken token) at NuGet.Protocol.ServiceIndexResourceV3Provider.GetServiceIndexResourceV3(SourceRepository source, DateTime utcNow, ILogger log, CancellationToken token) --- End of inner exception stack trace --- at NuGet.Protocol.ServiceIndexResourceV3Provider.GetServiceIndexResourceV3(SourceRepository source, DateTime utcNow, ILogger log, CancellationToken token) at NuGet.Protocol.ServiceIndexResourceV3Provider.TryCreate(SourceRepository source, CancellationToken token) at NuGet.Protocol.Core.Types.SourceRepository.GetResourceAsync[T](CancellationToken token) at NuGet.Protocol.Providers.VulnerabilityInfoResourceV3Provider.TryCreate(SourceRepository source, CancellationToken token) at NuGet.Protocol.Core.Types.SourceRepository.GetResourceAsync[T](CancellationToken token) at NuGet.Commands.VulnerabilityInformationProvider.GetVulnerabilityInfoAsync() at NuGet.Commands.VulnerabilityInformationProvider.GetVulnerabilityInformationAsync(CancellationToken cancellationToken) at NuGet.Commands.Restore.Utility.AuditUtility.GetAllVulnerabilityDataAsync(CancellationToken cancellationToken) at NuGet.Commands.Restore.Utility.AuditUtility.CheckPackageVulnerabilitiesAsync(CancellationToken cancellationToken) at NuGet.Commands.RestoreCommand.PerformAuditAsync(EnabledValue enableAudit, IEnumerable1 graphs, TelemetryActivity telemetry, CancellationToken token) at NuGet.Commands.RestoreCommand.PerformAuditAsync(EnabledValue enableAudit, IEnumerable
1 graphs, TelemetryActivity telemetry, CancellationToken token) at NuGet.Commands.RestoreCommand.ExecuteAsync(CancellationToken token) at NuGet.Commands.RestoreCommand.PerformAuditAsync(EnabledValue enableAudit, IEnumerable1 graphs, TelemetryActivity telemetry, CancellationToken token) at NuGet.Commands.RestoreCommand.PerformAuditAsync(EnabledValue enableAudit, IEnumerable
1 graphs, TelemetryActivity telemetry, CancellationToken token) at NuGet.Commands.Restore.Utility.AuditUtility.CheckPackageVulnerabilitiesAsync(CancellationToken cancellationToken) at NuGet.Commands.RestoreCommand.ExecuteAsync(CancellationToken token) at NuGet.Commands.RestoreRunner.ExecuteAsync(RestoreSummaryRequest summaryRequest, CancellationToken token) at NuGet.Commands.RestoreRunner.ExecuteAsync(RestoreSummaryRequest summaryRequest, CancellationToken token) at NuGet.Commands.RestoreRunner.ExecuteAndCommitAsync(RestoreSummaryRequest summaryRequest, IRestoreProgressReporter progressReporter, CancellationToken token) at NuGet.Commands.RestoreRunner.CompleteTaskAsync(List1 restoreTasks) at NuGet.Commands.RestoreRunner.RunAsync(IEnumerable
1 restoreRequests, RestoreArgs restoreArgs, CancellationToken token) at NuGet.Commands.RestoreRunner.RunAsync(RestoreArgs restoreContext, CancellationToken token) at NuGet.Build.Tasks.BuildTasksUtility.RestoreAsync(DependencyGraphSpec dependencyGraphSpec, Boolean interactive, Boolean recursive, Boolean noCache, Boolean ignoreFailedSources, Boolean disableParallel, Boolean force, Boolean forceEvaluate, Boolean hideWarningsAndErrors, Boolean restorePC, Boolean cleanupAssetsForUnsupportedProjects, ILogger log, CancellationToken cancellationToken) at NuGet.Build.Tasks.RestoreTask.ExecuteAsync(ILogger log)
UPDATE I updated the NuGet.Config file as above
UPDATE 2
The solution recommended by @wade zhou - MSFT to use this configuration
--valid-authentication-types basic
with the PAT (Personal Access Token) works perfectly. Thanks
But i always get an 401 Unauthorized error.
It appears you have disabled the DevOps feed myfeed
in Nuget.Config. Please remove it from <disabledPackageSources>
section.
In addtion, the 401
error indicates the user doesn't have permission or PAT is not correct. please follow below items to check:
Generate a new PAT token with package
read
scope at least. Put it in the nuget.config.
Specify the Nuget.config file in the command:
$ dotnet restore <project>.csproj --configfile NuGet.config --verbosity detailed
In WSL, make sure it can access the target Azure devops server site.
The restore result on my side for your reference: