.Net

Prev Next

Available in Classic and VPC

This section describes how to create and use .Net(core) actions in a variety of ways, and includes application examples.

Note

To compile, test, and compress .NET Core projects, you must install .NET Core SDKlocally and set the DOTNET_HOME environment variable to the location of the dotnet executable file.

Create action

To create an action, you must first understand the .NET action structure. .NET Core actions consist of .NET Core libraries and Main function structured as follows:

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

Create a C# project named NCP.CloudFunctions.Example.Dotnet to check an example for action creation.

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

Then install Newtonsoft.Json, NuGet packages for using json.

dotnet add package Newtonsoft.Json -v 12.0.1

Here's an example of creating an action:

  1. Write an 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 contents.

    dotnet publish -c Release -o out
    
  3. Run the command to create a zip file of the published contents.

    cd out
    zip -r -0 helloDotNet.zip *
    
  4. Create an action by uploading the created zip file.

cloudfunctions-exmaple-net_v2_01_ko

  • When creating an action in .NET format, you must enter the Main function in the format {Assembly}::{Class Full Name}::{Method} as shown in this example.
NCP.CloudFunctions.Example.Dotnet::NCP.CloudFunctions.Example.Dotnet.Hello::Main

cloudfunctions-example-run-dotnet_mainFunc_ko