• PDF


  • PDF

Available in Classic and VPC

This document describes how to create and use .NET (Core) actions in a variety of ways, and includes application examples.

  • Cloud Functions provides the .NET 2.2 version, which is an action container allowing execution of .NET code. The code can be run in an independent environment.
  • To compile, test, or compress a .NET Core project, .NET Core SDK should be installed in a local environment. The environment variable DOTNET_HOME should also be set to the location where the dotnet execution file is.

Create actions

To create an action, you have to understand the .NET action structure first. A .NET Core action structure consists of a .NET Core library and main function.

public Newtonsoft.Json.Linq.JObject Main(Newtonsoft.Json.Linq.JObject);

To view an action creation example, create a C# project under the name NCP.CloudFunctions.Example.Dotnet.

dotnet new classlib -n NCP.CloudFunctions.Example.Dotnet -lang "C#" -f netstandard2.0
cd NCP.CloudFunctions.Example.Dotnet

Afterward, install the Newtonsoft.Json and NuGet packages to use JSON.

dotnet add package Newtonsoft.Json -v 12.0.1

Now, the following shows the example to create the action.

  1. Create action code, Hello.cs.

    using System;
    using Newtonsoft.Json.Linq;
    namespace NCP.CloudFunctions.Example.Dotnet
        public class Hello
            public JObject Main(JObject args)
                string name = "stranger";
                if (args.ContainsKey("name")) {
                    name = args["name"].ToString();
                JObject message = new JObject();
                message.Add("greeting", new JValue($"Hello, {name}!"));
                return (message);
  2. Run the command to publish the project content.

    dotnet publish -c Release -o out
  3. Run the command, and create the published content as a ZIP file.

    cd out
    zip -r -0 helloDotNet.zip *
  4. Upload the ZIP file created to create the action.

    • When creating a .NET action, the Main function must be written in a format such as {Assembly}::{Class Full Name}::{Method}. The input for the above example should be entered in the following format.

Was this article helpful?

What's Next