--- title: ".Net" slug: "cloudfunctions-example-net" tags: ["Cloud Functions"] updated: 2026-09-17T09:31:52Z published: 2026-09-17T09:31:52Z canonical: "guide.ncloud-docs.com/cloudfunctions-example-net" --- > ## Documentation Index > Fetch the complete documentation index at: https://guide.ncloud-docs.com/llms.txt > Use this file to discover all available pages before exploring further. # .Net Classic/VPC環境で利用できます。 .Net(core)形式のアクションを作成して多様に活用する方法と、そのユースケースを紹介します。 参考 .Net Coreプロジェクトをコンパイル、テスト、圧縮するためには、[.Net Core SDK](https://dotnet.microsoft.com/download)をローカルにインストールし、環境変数の DOTNET_HOMEを dotnet実行ファイルがある場所に設定する必要があります。 ## アクション作成 アクションを作成するには、まず.Netアクションの構造を理解する必要があります。.Net Coreアクションは次のような.Net Coreライブラリと Main関数の構造になっています。 ``` public Newtonsoft.Json.Linq.JObject Main(Newtonsoft.Json.Linq.JObject); ``` アクション作成ユースケースを確認するために NCP.CloudFunctions.Example.Dotnetという C#プロジェクトを作成します。 ``` dotnet new classlib -n NCP.CloudFunctions.Example.Dotnet -lang "C#" -f netstandard2.0 cd NCP.CloudFunctions.Example.Dotnet ``` 次に、jsonを使用するために [Newtonsoft.Json](https://www.newtonsoft.com/json)、[NuGet](https://docs.microsoft.com/ko-kr/nuget/what-is-nuget)パッケージをインストールします。 ``` dotnet add package Newtonsoft.Json -v 12.0.1 ``` アクションを作成するユースケースは、次の通りです。 1. アクションコード 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. プロジェクト内容を発行するためのコマンドを実行します。 ``` dotnet publish -c Release -o out ``` 3. コマンドを実行し、発行された内容を zipファイルに作成します。 ``` cd out zip -r -0 helloDotNet.zip * ``` 4. 作成された zipファイルをアップロードしてアクションを作成します。 ![cloudfunctions-exmaple-net_v2_01_ko](https://cdn.document360.io/6998976f-9d95-4df8-b847-d375892b92c2/Images/Documentation/cloudfunctions-example-net_v2_01_ja.png?sv=2026-02-06&spr=https&st=2026-10-30T16%3A57%3A19Z&se=2026-10-30T17%3A57%3A19Z&sr=c&sp=r&sig=kFaRprK384uYEHQxUYEGicrpdVhBbfbqbzLbtpb4S5M%3D) - .Net形式でアクションの作成時、`Main`関数は{Assembly}::{Class Full Name}::{Method}の形式で作成する必要があるため、上記ユースケースの場合は次のような形式で Main関数を入力する必要があります。 ``` NCP.CloudFunctions.Example.Dotnet::NCP.CloudFunctions.Example.Dotnet.Hello::Main ``` ![cloudfunctions-example-run-dotnet_mainFunc_ko](https://cdn.document360.io/6998976f-9d95-4df8-b847-d375892b92c2/Images/Documentation/cloudfunctions-example-run-dotnet_mainFunc_ja.png?sv=2026-02-06&spr=https&st=2026-10-30T16%3A57%3A19Z&se=2026-10-30T17%3A57%3A19Z&sr=c&sp=r&sig=kFaRprK384uYEHQxUYEGicrpdVhBbfbqbzLbtpb4S5M%3D)