Power Automate Desktop (PAD) does not natively support running C# code directly, but there are workarounds to execute C# logic using external scripts or compiled binaries.
Here are several practical ways to run C# code within Power Automate Desktop:
Method 1: Compile C# Code to EXE and Run It
You can write your C# code in Visual Studio or .NET CLI, compile it to an .exe file, and then use PAD to execute it.
Steps:
Create your C# console app:
In Visual Studio or using the CLI:
dotnet new console -n MyCSharpApp
cd MyCSharpApp
Write your logic in Program.cs:
csharp
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello from C#!");
// Your logic here
}
}
Build the application:
dotnet build -c Release
Locate the .exe file (usually in bin\Release\netX.X\) and copy it to a known location.
In Power Automate Desktop:
Use the "Run a program" action.
Set the path to your .exe.
Method 2: Use PowerShell to Run Inline C# Code
PowerShell can compile and run C# code dynamically. PAD supports PowerShell scripting.
Example PowerShell Script (in PAD):
powershell
Add-Type -TypeDefinition @"
using System;
public class HelloWorld {
public string SayHello() {
return "Hello from C#!";
}
}
"@
$instance = New-Object HelloWorld
$instance.SayHello()
Use the "Run PowerShell script" action in PAD.
Capture output if needed.
Method 3: Use .NET Scripting with External Tool Integration
If you want more flexibility without compiling .exe files every time, you can:
Use a script host like ScriptCS (C# scripting).
Or run .csx files with .NET SDK.
Then invoke them from PAD using the "Run a program" or "Run PowerShell" actions.
Method 4: Use Power Automate (Cloud) + Azure Functions (C#)
If you're open to cloud-based execution:
Write C# logic in Azure Functions.
Trigger them from PAD using HTTP actions (via REST API).
If I have answered your question, please mark it as the preferred solution ✅ . If you like my response, please give it a Thumbs Up 👍.
Regards,
Riyaz