无法将ASP.NET Web API发布到Azure应用程序服务(使用SwashBuckle)

xe55xuns  于 2022-11-25  发布在  .NET
关注(0)|答案(3)|浏览(161)

我有一个应用服务已经在Azure中运行了一段时间。我刚刚将它更新到.NET 6. 0(并在本地安装了Swashbuckle.aspnetcore.cli v6. 2. 3)。
我无法发布到Azure。当我第一次尝试时,它告诉我它找不到aspnetcore3.0,它只能找到.NET 5.1.4和.NET 6.0.1的已安装版本。
以下说明如下:https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1485
我在我的项目中添加了一个global.json:

{
    "sdk":
    {
        "version": "6.0.1",
        "rollForward": "latestPatch"
    }
}

现在,当我尝试发布时,我得到以下错误:

Failed to install DotNet CLI tool 'swashbuckle.aspnetcore.cli'.  Error dotnet tool restore

Could not execute because the application was not found or a compatible .NET SDK is not installed.
Possible reasons for this include:
  * You intended to execute a .NET program:
      The application 'tool' does not exist.
  * You intended to execute a .NET SDK command:
      A compatible installed .NET SDK for global.json version [6.0.1] from [C:\Projects\MyProject\global.json] was not found.
      Install the [6.0.1] .NET SDK or update [C:\Projects\MyProject\global.json] with an installed .NET SDK:

如何发布我的应用服务?

cbwuti44

cbwuti441#

您可以尝试的一个简单解决方法是-

  • 这与导致问题的发布配置文件有关。
  • 创建一个新的,并检查它现在是否正常工作。

此外,请尝试引用此link

1rhkuytd

1rhkuytd2#

对于发现此问题的其他人,我最终通过编辑项目根文件夹中“.config”文件夹中的文件“dotnet-tools.json”,并将swashbuckle.aspnetcore.api的版本从5.6.3更改为6.3.0,修复了此问题。
我还更新到了swashbuckle 6.3.0,并将global.json更改为:

{
    "sdk":
    {
        "version": "5.6.3",
        "rollForward": "latestMajor"
    }
}

请注意使用latestMajor而不是latestPatch。

14ifxucb

14ifxucb3#

在我的例子中,Swashbuckle.Core库导致了这个问题,我从NuGet安装了这个库来尝试一些东西。当我导航到Dependencies -〉Packages时,我看到一个错误,指出这个包与.NET Framework版本兼容:v4.6、v4.7、v4.8,不适用于目标框架net6.0。
因此,卸载这个NuGet包让我运行!顺便说一句,当我试图将我的WebApi发布到Azure应用服务时,发生了错误(只是为了设置一些上下文)。

相关问题