【问题标题】:Failed to retrieve template packages from provider 'Global Settings无法从提供商\'全局设置中检索模板包
【发布时间】:2023-01-23 16:26:40
【问题描述】:

我正在尝试运行dotnet new install .\ ,但出现以下错误:

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)

我什至尝试运行dotnet new list,它返回 VS2022 包,但不是我在出现上述错误之前安装的包。另外,当我得到 dotnet new list 时,我再次在模板列表之前得到以下内容

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

我尝试再次安装 .NET 7 SDK,但仍然出现相同的错误

【问题讨论】:

    标签: c# .net .net-7.0


    【解决方案1】:

    它通常是由 dotnet new 命令的配置问题引起的,特别是用于从提供程序检索模板包的全局设置。

    你可以尝试这几件事来解决这个问题

    1. 删除 global.json 文件。此文件包含 dotnet new 命令的全局设置,如果它损坏或丢失,可能会导致您看到的错误。该文件通常位于应用程序的根目录中

    2. 清除 NuGet 包缓存。缓存可能已损坏并阻止 dotnet new 正常工作。 dotnet nuget locals all --clear

    【讨论】:

    • 这个答案本身没什么意义,如果脱离上下文实际上是错误的。它要么是从一篇更大的文章中复制出来的,要么就是一个彻头彻尾的伪造的 ChatGPT 答案。没有原始文章就没有意义-global.json 包含 SDK 版本信息只要.它不需要也不会存在,除非有人添加它以使用特定的 SDK 版本。至于clear the cache,这是一般性建议,可能与问题无关,也可能无关
    猜你喜欢
    • 2018-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-08
    • 1970-01-01
    • 2018-05-07
    相关资源
    最近更新 更多