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

发布于 2025-01-11 09:32:21 字数 1204 浏览 0 评论 0 原文

我有一个应用服务已经在 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:

如何发布我的应用程序服务?

I have an App Service that has been running in Azure for a while. I have just updated it to .NET 6.0 (and installed Swashbuckle.aspnetcore.cli v6.2.3 locally).

I cannot publish to Azure. When I first tried it told me it couldn't find aspnetcore3.0 and the only installed versions it could find were .NET 5.1.4 and .NET 6.0.1.

Following instructions here:
https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1485

I added a global.json to my project:

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

Now when I try and publish I get the following error:

    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:

How can I publish my app service?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

不一样的天空 2025-01-18 09:32:21

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

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

另外,请尝试参考此链接

One of the simple workaround that you can try is -

  • It had something to do with the publish profile that was causing the issue.
  • Create a new one, and check whether now it functions properly.

Also, please try referring this link.

岛歌少女 2025-01-18 09:32:21

对于发现此问题的其他人,我最终通过编辑项目根文件夹中“.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。

To anyone else that finds this issue, I finally fixed it by editing the file "dotnet-tools.json" in the ".config" folder in the project root folder, and changing the version of swashbuckle.aspnetcore.api from 5.6.3 to 6.3.0.

I also updated to swashbuckle 6.3.0, and changed global.json to be:

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

Note the use of latestMajor rather than latestPatch.

秋心╮凉 2025-01-18 09:32:21

就我而言,Swashbuckle.Core 库导致了此问题,我从 NuGet 安装该库来尝试一些东西。当我导航到“依赖项”->包,我看到一个错误,指出该包的兼容性适用于 .NET Framework 版本:v4.6、v4.7、v4.8,而不适用于目标框架 net6.0。

因此,卸载这个 NuGet 包让我继续运行!顺便说一句,当我尝试将 WebApi 发布到 Azure 应用服务时,发生了错误(只是为了设置一些上下文)。

In my case, the Swashbuckle.Core library was causing this issue which I installed from NuGet to try something out. When I navigated to Dependencies -> Packages, I saw an error which stated that this package's compatibility is for that of .NET Framework versions: v4.6, v4.7, v4.8 and NOT for the target framework net6.0.

Therefore, uninstalling this NuGet package got me running! BTW, the error occurred (just to set some context), when I attempted to publish my WebApi to Azure App Service.

一杯敬自由 2025-01-18 09:32:21

就我而言,我最初错过了安装所有三个必需的 Swagger 包。安装它们后,我的问题得到了解决。 输入图片此处描述

In my case, I initially missed installing all three required Swagger packages. After installing them, my issue was resolved. enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文