Debug Azure Function locally with Visual Studio 2019

Jalza 781 Reputation points
2022-12-02T07:28:15.92+00:00

I want to run a task every day at 5 am to write some data to the database to create some reports. For that I thought I could use Azure Functions (Timer trigger). My goal is to first debug the function locally (using a local database) before publishing it to Azure. For this I have created a new Azure Functions project in Visual Studio 2019 with the following parameters:

  • .NET 5.0 (Isolated).
  • Timer trigger.
  • Storage Account (AzureWebJobsStorage): Storage Emulator.
  • Schedule: 0 0 5 * * *

If I try to run the function (pressing F5 in the keyboard) without any changes to the code, it opens a CMD window with the colored Azure Functions logo created with characters and then the following error:

Error: unknown argument --port

In project properties > Debug tab > Application arguments I have
--port 7282
. I have a systray icon with this message: "Storage emulator is started".

I tried the answer of What is the simplest way to run a timer-triggered Azure Function locally once? question, but I get the same error.

What do I have to do to debug the function locally? Do I need to install any specific tool?

----------

If it helps, I have the following files:

Program.cs

public class Program  
{  
    public static void Main()  
    {  
        var host = new HostBuilder()  
            .ConfigureFunctionsWorkerDefaults()  
            .Build();  

        host.Run();  
    }  
}  

Function1.cs:

public class Function1  
{  
    private readonly ILogger _logger;  

    public Function1(ILoggerFactory loggerFactory)  
    {  
        _logger = loggerFactory.CreateLogger<Function1>();  
    }  

    [Function("Function1")]  
    public void Run([TimerTrigger("0 0 5 * * *")] MyInfo myTimer)  
    {  
        _logger.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");  
        _logger.LogInformation($"Next timer schedule at: {myTimer.ScheduleStatus.Next}");  
    }  
}  

public class MyInfo { ... }  
public class MyScheduleStatus { ... }  
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,185 questions
0 comments No comments
{count} votes

Accepted answer
  1. Arun Siripuram 886 Reputation points
    2022-12-03T06:28:53.29+00:00

    @Jalza
    Understood that your facing issue with Azure Functions while running locally. Please follow the below steps to try alternate options.

    1. Remove the launchSettings.json as you have a --port 7282 configured.
    2. Run the application
    3. There is an alternate option to mention in local.settings.json file. this file stores app settings and settings used by local development tools. Settings in the local.settings.json file are used only when you're running your project locally

    please refer https://learn.microsoft.com/en-us/azure/azure-functions/functions-develop-local
    if you still face issues, as this project looks like a sample project, you can share source code in github.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.