未调用 Azure Function 启动的配置

Posted

技术标签:

【中文标题】未调用 Azure Function 启动的配置【英文标题】:Azure Function startup's Configure not being called 【发布时间】:2022-01-18 18:19:48 【问题描述】:

我正在尝试在 .NET 5 (VS 2022) 中的 Azure Function 项目中创建非静态函数,但未调用 Startup Configure 方法。

这是我的入门课程

[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

【问题讨论】:

如果该类被标记为公开会怎样? @PeterBons 已经试过了,不行。 你的host.json是什么样的? 还有你的实际功能 哦,你在 Azure 中的设置?我想你的意思是它不能在 Azure 中工作,而不是在你的本地机器上? 【参考方案1】:

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

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

    Microsoft.Net.Sdk.functions添加到项目后,运行到同样的问题MSB4062错误如下:

通过引用这些 SO Thread1 和 Thread2,删除 Microsoft.Net.Sdk.functions 将解决编译问题。

【讨论】:

以上是关于未调用 Azure Function 启动的配置的主要内容,如果未能解决你的问题,请参考以下文章

Azure Durable Function Activity 似乎运行多次且未完成

在 Azure 持久函数上调用 CreateCheckStatusResponse 时,Azurite 未给出与 Azure 存储模拟器相同的结果

如何在启动类中使用 Azure Function 中的中间件

Azure Function v3 - 在启动中添加标识时“无法访问 Azure Functions 运行时”

VSCode中的Python Azure函数(HTTPTrigger)上的调试未正确启动Func Host Start

Azure Function IWebJobsStartup 实现中的 ExecutionContext