- Print
- PDF
.Net
- Print
- 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.
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.
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); } } }
Run the command to publish the project content.
dotnet publish -c Release -o out
Run the command, and create the published content as a ZIP file.
cd out zip -r -0 helloDotNet.zip *
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.NCP.CloudFunctions.Example.Dotnet::NCP.CloudFunctions.Example.Dotnet.Hello::Main
- When creating a .NET action, the