You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用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,也可以手动生成函数文件:

  1. 在项目中新建C#类文件UpdateApplications.cs
  2. 写入以下示例代码(按需调整定时器表达式):
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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 20:52:37