Nie*_*nch 8 c# azure azure-functions .net-5
我正在使用 .NET 5 并开发 Azure Functions。通过 Visual Studio 添加新的计时器触发器函数时,它会添加一个包含以下内容的文件:
public static class Function1
{
[FunctionName("Function1")]
public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
}
}
Run Code Online (Sandbox Code Playgroud)
我将其作为照片包含在此处,以强调它无法编译,因为 TimerTrigger 类不存在。
Intellisense 建议我添加以下内容:
using Microsoft.Azure.WebJobs;
Run Code Online (Sandbox Code Playgroud)
但这没有意义,因为那属于以前版本的 Azure Functions。果然,Intellisense 检测到了这一点并显示了这个错误。
那么如何在.NET 5中使用TimerTrigger呢?
也许因为这是相对较新的,似乎还没有关于此的文档或热门帖子。
尝试该Microsoft.Azure.Functions.Worker.Extensions.Timer软件包,如下所示:
由于在 .NET 隔离进程中运行的函数使用不同的绑定类型,因此它们需要一组唯一的绑定扩展包。
您将在 Microsoft.Azure.Functions.Worker.Extensions 下找到这些扩展包。
| 归档时间: |
|
| 查看次数: |
4403 次 |
| 最近记录: |