When you already have a C# console application that solves a problem, but you need to expose it to automation platforms like Power Automate, the best solution is to transform it into an Azure Function. With this approach, your existing logic can be called via HTTP, integrated with workflows, and scaled automatically in the cloud.


From Console App to Azure Function: How to Expose Your Code to Power Automate

When you already have a C# console application that solves a problem, but you need to expose it to automation platforms like Power Automate, the best solution is to transform it into an Azure Function. With this approach, your existing logic can be called via HTTP, integrated with workflows, and scaled automatically in the cloud.

In this article, we’ll cover step by step how to migrate your code.


Step 1 – Isolate Your Business Logic

Console apps typically have everything inside Program.cs. For example:

static void Main(string[] args)
{
    var result = MyBusinessLogic.Run();
    Console.WriteLine(result);
}

To reuse this logic in Azure Functions, move it into a static class:

public static class MyBusinessLogic
{
    public static string Run()
    {
        // Original console app code
        return "Hello from Console App!";
    }
}


Step 2 – Create a New Azure Function Project

  1. Open Visual Studio or VS Code.
  2. Create a new project → Azure Functions.
  3. Select HTTP Trigger.
  4. Choose the latest .NET runtime (6 or 8 recommended).

This generates a starting point like Function1.cs.


Step 3 – Connect Your Logic to the Function

Replace the generated code with this structure:

using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;

namespace MyAzureFunctionApp
{
    public class Function1
    {
        private readonly ILogger _logger;

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

        [Function("Function1")]
        public HttpResponseData Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req)
        {
            _logger.LogInformation("Azure Function received a request.");

            var result = MyBusinessLogic.Run();

            var response = req.CreateResponse(HttpStatusCode.OK);
            response.Headers.Add("Content-Type", "application/json; charset=utf-8");
            response.WriteString($"{{\"result\":\"{result}\"}}");

            return response;
        }
    }

    public static class MyBusinessLogic
    {
        public static string Run()
        {
            // Original console app code
            return "Hello from Azure Function!";
        }
    }
}

Now, your function wraps the same logic you had in the console app.


Step 4 – Deploy the Function to Azure

You can deploy in different ways:

  • Visual Studio: Right-click the project → Publish → Azure Function App.
  • Azure CLI: func azure functionapp publish <YourFunctionAppName>

Step 5 – Get the Function URL

Once published, go to the Azure Portal:

  • Open your Function App.
  • Select your function.
  • Click Get Function URL → copy the link (it contains a code=xxxx parameter).

Step 6 – Integrate with Power Automate

In Power Automate:

  1. Create a new flow.
  2. Add the HTTP connector.
  3. Configure:
    • Method: POST or GET.
    • URL: paste the Function URL.
    • Headers: Content-Type: application/json.
    • Body: your parameters (if required).

The Azure Function response can now be used in any subsequent step of your flow.


Technical Summary

StepActionResult
1Move logic from Program.cs into a static classMyBusinessLogic.Run() reusable
2Create Azure Function project (HTTP Trigger)Cloud-ready API
3Call your logic inside the HTTP TriggerFunction returns JSON
4Deploy to AzureFunction App online
5Copy Function URLPublic endpoint
6Configure Power Automate HTTP actionFlow invokes the function

Conclusion

By wrapping your existing console app logic in an Azure Function, you turn it into a lightweight cloud API. This allows Power Automate (and any other service capable of making HTTP calls) to use your code seamlessly.

This approach avoids rewriting your entire solution, while giving you the scalability and integration power of the Azure ecosystem.

Edvaldo Guimrães Filho Avatar

Published by