如何用Azure Functions Core Tools为dotnet-isolated(net8.0)函数应用添加新函数?
解决dotnet-isolated模式下Azure Functions添加C#函数的错误问题
错误原因
你创建的是dotnet-isolated(.NET独立工作进程)模式的函数项目,而func new --language c#默认指向传统的in-process(进程内)模式C#项目,两者worker runtime不匹配,因此触发报错。
正确CLI命令
使用c#-isolated作为语言参数,执行以下命令即可添加匹配的Timer Trigger函数:
func new --language c#-isolated --template "Timer trigger" --name UpdateApplications
手动创建函数(备选方案)
如果不想依赖CLI,也可以手动生成函数文件:
- 在项目中新建C#类文件
UpdateApplications.cs - 写入以下示例代码(按需调整定时器表达式):
using Microsoft.Azure.Functions.Worker; using Microsoft.Extensions.Logging; namespace YourProjectNamespace; // 替换为你的项目命名空间 public class UpdateApplications { private readonly ILogger<UpdateApplications> _logger; public UpdateApplications(ILogger<UpdateApplications> logger) { _logger = logger; } [Function("UpdateApplications")] public void Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer) { _logger.LogInformation("Timer trigger executed at: {Time}", DateTime.Now); _logger.LogInformation("Next run scheduled at: {NextTime}", myTimer.ScheduleStatus.Next); } }
内容的提问来源于stack exchange,提问作者Shuzheng
相关产品推荐
相关产品推荐

