Creating Azure Functions with C# Script (.csx)
Azure Functions is a serverless technology that allows you to process events. It allows you to act on a blob being added, for example, or a message being published on a queue or an HTTP request. You can write an Azure function in Python, PowerShell, C#, Node, or Java.
When building a project in C#, you need to create a .csproj. To create an Azure Function, you’ll need to introduce a class, add bindings, and so forth. Then you need to compile the project and deploy the manifest to Azure.
But sometimes a full-blown C# solution is overkill. In those cases, maybe an Azure Function with C# Script (.csx) will suffice. In this article, you can read how to create a C# script Azure function, add a trigger, and deploy it to Azure.
Creating a C# script Azure Function
To get started, you need the Azure Functions Core Tools. Install them by running the following command on Mac:
brew install azure/functions/azure-functions-core-tools
On Windows, use Chocolatey to install the Azure Functions Core Tools:
choco install azure-functions-core-tools
This introduces a new command-line tool called “func”.
Navigate to the folder where you want to create your Azure Function. Now run the following command:
func init --csx
This will create a host.json and a local.settings.json file. These files contain the metadata Azure Functions needs about how to run the function.
Create an (HTTP) trigger
For a function to get triggered, a trigger needs to be defined. Create it by typing the following command:
func new --csx
A list of trigger types is shown for you to choose from. Next, you’ll be asked to provide the name of the trigger. In this case, I’m creating an HTTP trigger named “Hello”.