Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timer Trigger with Azure Functions V3 (.NET 5)

I am using .NET 5 and developing Azure Functions. When adding a new Timer Trigger function through Visual Studio it adds a file with this content:

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}");
        }
    }

I'm including it as a photo here to highlight that it doesn't compile because the TimerTrigger class doesn't exist.

Intellisense suggests that I add the following using:

using Microsoft.Azure.WebJobs;

But that doesn't make sense, because that belongs to the previous version of Azure Functions. And sure enough, Intellisense detects this and show this error.

enter image description here

So how do I use TimerTrigger in .NET 5?

Maybe because this is relatively new, there seems to be no documentation or popular posts about this yet.

like image 826
Niels Brinch Avatar asked Jul 13 '21 10:07

Niels Brinch


1 Answers

Try the Microsoft.Azure.Functions.Worker.Extensions.Timer package, as documented here:

Because functions that run in a .NET isolated process use different binding types, they require a unique set of binding extension packages.

You'll find these extension packages under Microsoft.Azure.Functions.Worker.Extensions.

Direct link to NuGet

like image 57
Peter Bons Avatar answered Oct 18 '22 02:10

Peter Bons