如何部署到 Azure Function 应用程序部署槽?

问题描述 投票:0回答:1

我创建了一个函数应用部署槽。我已从 Visual Studio 发布,它表示您的 Function 应用程序已准备就绪。 但是当我进入功能应用程序插槽时,我看不到任何功能,它说

  We were not able to load some functions in the list due to errors. Refresh the page to 
 try again
  Encountered an error (InternalServerError) from host runtime.

页面顶部写着:

  microsoft.azure.webjobs.extensions.durabletask: Task Hub name must be specified in 
  host.json when using slots. Specified name must not equal the default HubName 
  (funcapp1).

host.json 是在我的应用程序中还是我需要在 Azure 上执行? 我还可以给它起任何名字还是我需要创建一个集线器?

当我部署到插槽时,它与直接部署到功能应用程序相同,如下所示:

az functionapp 部署源 config-zip -g "MyResourceGroup" -n “appslotname”--src $sourceZipPath ?

azure azure-functions
1个回答
0
投票

要将函数从 Visual Studio 部署到

Deployment slots
,请从列表中选择要部署到的部署槽。

注意:

Production
如果您未从列表中选择任何插槽,则插槽将不会在列表中可用,因为它是默认插槽。

我部署了一个示例 Http 触发器功能。

Function.cs
:

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;

namespace FunctionApp4
{
    public class Function
    {
        private readonly ILogger<Function> _logger;

        public Function(ILogger<Function> logger)
        {
            _logger = logger;
        }

        [Function("Function")]
        public IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req)
        {
            _logger.LogInformation("C# HTTP trigger function processed a request.");
            return new OkObjectResult("Welcome to Azure Functions!");
        }
    }
}

如何查看 Microsoft.NET.Sdk.Functions 版本?

您可以在

.csproj
文件中定义版本。我的函数版本是4 dotnet 版本是 8

注意:

In-process
型号使用
Microsoft.Azure.Webjobs.extension
封装,
Isolated Process
使用
Microsoft.Azure.Functions.Worker
封装。

确保您在正确的流程模型中使用正确的包。

FunctionApp4.csproj
:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.1" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.1.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
  </ItemGroup>
</Project>

OUTPUT

© www.soinside.com 2019 - 2024. All rights reserved.