Azure Function 启动的配置未被调用

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

我正在尝试在 .NET 5 (VS 2022) 中的 Azure Function 项目中创建非静态函数,并且

Startup
配置方法未被调用。

这是我的入门课程

[assembly: FunctionsStartup(typeof(AuthenticationGateway.Functions.Startup))]
namespace AuthenticationGateway.Functions
{
    class Startup : FunctionsStartup //public or not, still does not get called.
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            
            //break point here never gets hit...
            
        }

        
    }


}

这是有问题的函数:

namespace AuthenticationGateway.Functions
{
    public class CreationConnection
    {
        private AuthenticationGatewayContext Context { get; set; }

        public CreationConnection(AuthenticationGatewayContext context)
        {
            Context = context;
        }

        [Function("CreationConnection")]
        public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequestData req,
            FunctionContext executionContext)
        {            

            var response = req.CreateResponse(HttpStatusCode.OK);

            return response;
        }
    }
}

我尝试对

Configure
中的所有代码进行注释,以防出现问题,但也不起作用。也尝试将启动类标记为
public
,不行。

以下是相关项目的依赖项

它们不是项目在创建 Azure Function 项目时具有的默认依赖项,但当我尝试其他解决方案来解决问题时,它导致我插入这些依赖项。

这是启动项目时控制台所说的内容:

Azure Functions 核心工具核心工具版本:3.0.3904 提交 哈希:c345f7140a8f968c5dbc621f8a8374d8e3234206(64 位)函数 运行时版本:3.3.1.0

我错过了什么吗?

编辑:我已恢复到以下依赖项,因为之前的依赖项已实现,因此在项目中找不到任何功能。

this页面上,它说必须安装以下依赖项:

Microsoft.Azure.Functions.Extensions
Microsoft.NET.Sdk.Functions package version 1.0.28 or later
Microsoft.Extensions.DependencyInjection (currently, only version 3.x and earlier supported)

我已经这样做了,除了最后一个,因为它似乎与 .NET 5 不兼容。此外,该项目现在无法构建:

error MSB4062: The "GenerateFunctionMetadata" task could not be loaded from the assembly
c# azure .net-core azure-functions asp.net-core-5.0
2个回答
0
投票

我尝试按照以下步骤重现您遇到的相同问题:

  1. 在 VS2022 中创建 Azure Functions(堆栈:.Net5-v3)。
  2. 在将
    Microsoft.Net.Sdk.functions
    添加到项目之前,已构建成功。

  1. Microsoft.Net.Sdk.functions
    添加到项目后,它运行到了相同的问题MSB4062错误,如下所示:

通过引用这些SO Thread1Thread2,删除

Microsoft.Net.Sdk.functions
将解决编译问题。


0
投票

就我而言,我缺少命名空间上的程序集注释:

[assembly: FunctionsStartup(typeof(MyApp.Functions.Startup))] // this is what was missing
namespace MyApp.Functions;

internal class Startup : FunctionsStartup
{
    public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
    {
        // app configure stuff
    }

    public override void Configure(IFunctionsHostBuilder builder)
    {
        // configure stuff
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.