Home > Net >  Failed to retrieve template packages from provider 'Global Settings
Failed to retrieve template packages from provider 'Global Settings

Time:01-23

I'm trying to run dotnet new install .\ and I get the following error:

Error: Failed to retrieve template packages from provider 'Global Settings'.
Details: Error reading JObject from JsonReader. Path '', line 0, position 0.
Error reading JObject from JsonReader. Path '', line 0, position 0.
   at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
   at Microsoft.TemplateEngine.JExtensions.ReadObject(IPhysicalFileSystem fileSystem, String path)
   at Microsoft.TemplateEngine.Edge.BuiltInManagedProvider.GlobalSettings.GetInstalledTemplatePackagesAsync(CancellationToken cancellationToken)
   at Microsoft.TemplateEngine.Edge.BuiltInManagedProvider.GlobalSettingsTemplatePackageProvider.InstallAsync(IEnumerable`1 installRequests, CancellationToken cancellationToken)
   at Microsoft.TemplateEngine.Cli.TemplatePackageCoordinator.EnterInstallFlowAsync(InstallCommandArgs args, CancellationToken cancellationToken)
   at Microsoft.TemplateEngine.Cli.Commands.InstallCommand.ExecuteAsync(InstallCommandArgs args, IEngineEnvironmentSettings environmentSettings, TemplatePackageManager templatePackageManager, InvocationContext context)
   at Microsoft.TemplateEngine.Cli.Commands.BaseCommand`1.InvokeAsync(InvocationContext context)

I have even try to run dotnet new list it returns the VS2022 packages but not the ones that I had previously installed before getting the above error. Also when I get dotnet new list I'm again getting the below before the list of templates

Error: Failed to retrieve template packages from provider 'Global Settings'.
Details: Error reading JObject from JsonReader. Path '', line 0, position 0.

I tried to install .NET 7 SDK again and still gives the same errors

CodePudding user response:

It is typically caused by an issue with the configuration of the dotnet new command, specifically with the global settings that are used to retrieve template packages from the provider.

You can try those few things to resolve this issue

  1. Delete the global.json file. This file contains the global settings for the dotnet new command, and if it's corrupt or missing, it can cause the error you're seeing. This file is typically located in the root directory of your application

  2. Clear the NuGet package cache. The cache may have become corrupted and is preventing dotnet new from working properly. dotnet nuget locals all --clear

CodePudding user response:

For anyone out there spending his hours trying to find what is the issue causing this, I found the solution to this. Based on this issue

<user folder>\.templateengine\packages.json The package.json file was empty. I deleted it and run dotnet new list and issue was resolved

  • Related