.Net
    • PDF

    .Net

    • PDF

    Article Summary

    Classic/VPC 환경에서 이용 가능합니다.

    .Net(core) 형식의 액션을 생성하고 다양하게 활용하는 방법과 예제를 소개합니다.

    참고

    .Net Core 프로젝트를 컴파일, 테스트 및 압축하기 위해서는 .Net Core SDK를 로컬에 설치하고 환경변수 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, 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 파일을 업로드하여 액션을 생성해 주십시오.
      compute-15-2-601_ko

      • .Net 형식으로 액션 생성 시 Main 함수는 {Assembly}::{Class Full Name}::{Method}의 형태로 작성해야 하기 때문에 위 예제의 경우 다음과 같은 형태로 Main 함수를 입력하여야 합니다.
        NCP.CloudFunctions.Example.Dotnet::NCP.CloudFunctions.Example.Dotnet.Hello::Main
        
        cloudfunctions-example-run-dotnet_mainFunc_ko

    이 문서가 도움이 되었습니까?

    What's Next
    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.