Announcement: Introducing .NET 8 Custom Code support for Azure Logic Apps (Standard) – Preview
Introduction
The support for .NET Framework custom code in Logic App Standard has been helping customer to call compiled custom code from the built-in action, offering the flexibility and control needed to solve tough integration problems.
We are excited to announce that this feature has been extended to support .NET 8 based workloads as well. This means that you can now use the latest version of .NET to write your custom code logic and invoke it from a logic app action.
This document will show you how to use custom code support for Azure Logic Apps Standard with .NET 8.
Prerequisites
An Azure subscription. If you don’t have one, you can create a free account here.
Azure Logic Apps (Standard) extension for Visual Studio Code. You can install it from the Visual Studio Marketplace.
Using .NET 8 based custom code in logic app
Authoring, building, debugging and deploying experience are similar to the .NET framework based custom code project except that you choose the target framework as .NET 8 during the workspace creation.
More details on the .NET framework custom code support can be found in this blog- .NET Framework Custom Code for Azure Logic Apps (microsoft.com)
Create a Logic app workspace:
A logic app workspace template creates a workspace file and two sample projects. One of the projects will allow you to author custom code and the other project will be for authoring workflows.
You can create a new logic app workspace using the following steps:
Click on the Azure A in the left navigation followed by clicking on the Logic Apps icon and choose to Create a new logic app workspace
Select a folder for your project and choose a Workspace name.
Choose “Logic app with custom code project” as a project template.
Choose the target Framework as “.NET 8”
You will now be prompted to provide some values including:
Function name for your code project
A Namespace for your custom code
Workflow template for your first workflow (Stateful or Stateless)
A name for a workflow
Once you have completed those prompts you should see the following folder/file structure:
Authoring custom code
Within the Functions project, we will find a .cs file that contains the function that we created in the previous step. This function will include a default Run method that you can use to get started. This sample method demonstrates some of the capabilities found in calling in our custom code feature including passing different inputs and outputs including complex .NET types.
Note: You can modify the existing Run method to meet your needs, or you can copy and paste the function, including the [FunctionName(“function-name”)] declaration, and rename it to ensure there is a unique name associated with it. Modify this new function as you see fit. You will also need to ensure you don’t have two “Run” methods. Rename one of them so that you have unique method names.
Building custom code
Once you have completed authoring your code, we need to compile it. As part of the project template that was used to create your Function project, we have included build tasks that will compile your code and then bin place it into the lib/custom/net8 folder within your Logic App project. This folder is where workflows will look for custom code.
To build your code:
Click on Terminal – New Terminal
Select Functions
Within the command prompt, type in dotnet restore and hit enter.
Type dotnet build and hit enter.
Alternatively, you can also use the Run Build Task from the Terminal menu.
Verify in your Logic Apps project that you have dll files placed within libcustomnet8 folder. Also look for a sub folder with the same name as the Function name that you provided when provisioning template. Within this folder you should see a file called function.json that contains metadata about the function code that you just wrote.
Invoking the custom code from logic App workflow
Right mouse click on the workflow.json file that was provisioned during provisioning step and select Open Designer.
The designer will launch, and you will see a workflow presented that includes a Call a local function in this logic app action. Click on the action and you will see additional parameters populated.
You can explore these inputs by selecting Function Name dropdown, changing the default ZipCode or changing the TemperatureScale from Celsius to Fahrenheit.
Debugging custom code with workflow
Start Azurite for Table, Queue and blob services by running below commands on the View –> Command Palette, when prompted select Logic App project folder
Attach the debugger to Logic App project by clicking on Debug icon. Ensure that Attach to logic app (LogicApp) is selected and then click on green Play button.
To attach the debugger to .NET function project,
From the command palette, choose Debug: Attach to a .NET 5+ or .NET Core process
Choose the dotnet.exe process. If there are multiple dotnet.exe processes, choose the one which has the below path. <Drive>:Users<user>.azure-functions-core-toolsFunctionsExtensionBundlesMicrosoft.Azure.Functions.ExtensionBundle.Workflows<ExtensionBundleVersion>CustomCodeNetFxWorkernet8Microsoft.Azure.Workflows.Functions.CustomCodeNetFxWorker.dll
Set breakpoints in your code(.cs) and/or workflow(.json) by click next to the line number in the appropriate code file.
Right click on the workflow.json file and select Overview.
When the Overview page loads you should see a Callback URL populated and a Run trigger button enabled. Click on the Run trigger button.
You should now see your first breakpoint is activated. Use the VS Code commands to continue (F5), Step Into (F11) or Step Out (Shift + F11).
Deploying custom code
You can deploy custom code in the same manner as you deploy your workflow project. Please ensure that you build your custom code before deployment and that all dependent dlls are in the workflow’s lib/custom/net8 folder prior to deployment.
Custom code usage guidelines
Customers are encouraged to use .NET Framework custom code extensibility to complement their low code integration solutions that they build in Azure Logic Apps. In general, custom code extensibility can be used to:
Implement custom business logic
Custom parsing
Data validation
Message shaping
Calculations
Simple data transformations
Conversely, .NET Framework custom code extensibility is not a substitute for:
BizTalk pipeline components that implement streaming
Complex batching/debatching scenarios
Code processes that exceed more than 10 minutes in duration.
Large message data transformations.
Microsoft Tech Community – Latest Blogs –Read More