Google Cloud Platform에서 사용하는 .NET

무료로 사용해 보기 문서 보기

확장성이 높은 .NET 앱 개발, 배포, 디버그, 모니터링

  • check Visual Studio, 브라우저 기반 명령줄 또는 Windows PowerShell을 사용하여 .NET 앱 빌드
  • check 관용적인 .NET 라이브러리를 통해 GCP 서비스 사용
  • check C#을 사용하여 완전 관리형 SQL 데이터베이스 쿼리
  • check Google 기술을 사용하여 .NET Core 앱 확장
  • check 사전 구성된 ASP.NET Windows Server 시작
  • check Docker 컨테이너로 ASP.NET Core 앱 배포
광범위한 관용적 .NET 라이브러리

C#에서 가장 많이 사용되는 라이브러리를 활용하여 Google Cloud Platform 서비스에 액세스

Cloud Storage 내에 데이터 저장 및 보관
C#을 사용하여 완전 관리형 NoSQL 데이터베이스에 액세스
BigQuery로 데이터 분석 수행
Translation API를 사용하여 다양한 언어로 텍스트 번역
Vision API를 사용하여 이미지 분석
Cloud Storage 내에 데이터 저장 및 보관
1
NuGet 패키지 관리자, .NET CLI 또는 Paket CLI를 사용하여 클라이언트 라이브러리 설치
PM> Install-Package Google.Cloud.Storage.V1 -Version 2.1.0-beta01
.NET CLI> dotnet add package Google.Cloud.Storage.V1 --version 2.1.0-beta01
Paket CLI> paket add Google.Cloud.Storage.V1 --version 2.1.0-beta01
2
Cloud Platform 콘솔 프로젝트 설정
  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. Set up a GCP Console project.

    Set up a project

    Click to:

    • Create or select a project.
    • Enable the Cloud Storage API for that project.
    • Create a service account.
    • Download a private key as JSON.

    You can view and manage these resources at any time in the GCP Console.

  3. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the file path of the JSON file that contains your service account key. This variable only applies to your current shell session, so if you open a new session, set the variable again.

3
코드 작성
using Google.Cloud.Storage.V1;
using System;
using System.Diagnostics;

namespace GoogleCloudSamples
{
    class StorageQuickstart
    {
        static void Main(string[] args)
        {
            // Your Google Cloud Platform project ID.
            string projectId = "YOUR-PROJECT-ID";

            // Instantiates a client.
            StorageClient storageClient = StorageClient.Create();

            // The name for the new bucket.
            string bucketName = projectId + "-test-bucket";
            try
            {
                // Creates the new bucket.
                storageClient.CreateBucket(projectId, bucketName);
                Console.WriteLine($"Bucket {bucketName} created.");
            }
            catch (Google.GoogleApiException e)
            when (e.Error.Code == 409)
            {
                // The bucket already exists.  That's fine.
                Console.WriteLine(e.Error.Message);
            }
        }
    }
}
C#을 사용하여 완전 관리형 NoSQL 데이터베이스에 액세스
1
NuGet 패키지 관리자, .NET CLI 또는 Paket CLI를 사용하여 클라이언트 라이브러리 설치
PM> Install-Package Google.Cloud.Datastore.V1 -Version 2.0.0
.NET CLI> dotnet add package Google.Cloud.Datastore.V1 --version 2.0.0
Paket CLI> paket add Google.Cloud.Datastore.V1 --version 2.0.0
2
Cloud Platform 콘솔 프로젝트 설정
  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. Set up a GCP Console project.

    Set up a project

    Click to:

    • Create or select a project.
    • Enable the Cloud Datastore API for that project.
    • Create a service account.
    • Download a private key as JSON.

    You can view and manage these resources at any time in the GCP Console.

  3. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the file path of the JSON file that contains your service account key. This variable only applies to your current shell session, so if you open a new session, set the variable again.

3
코드 작성
using Google.Cloud.Datastore.V1;

namespace GoogleCloudSamples
{
    public class QuickStart
    {
        public static void Main(string[] args)
        {
            // Your Google Cloud Platform project ID
            string projectId = "YOUR-PROJECT-ID";

            // Instantiates a client
            DatastoreDb db = DatastoreDb.Create(projectId);

            // The kind for the new entity
            string kind = "Task";
            // The name/ID for the new entity
            string name = "sampletask1";
            KeyFactory keyFactory = db.CreateKeyFactory(kind);
            // The Cloud Datastore key for the new entity
            Key key = keyFactory.CreateKey(name);

            var task = new Entity
            {
                Key = key,
                ["description"] = "Buy milk"
            };
            using (DatastoreTransaction transaction = db.BeginTransaction())
            {
                // Saves the task
                transaction.Upsert(task);
                transaction.Commit();

                Console.WriteLine($"Saved {task.Key.Path[0].Name}: {(string)task["description"]}");
            }
        }
    }
}
BigQuery로 데이터 분석 수행
1
NuGet 패키지 관리자, .NET CLI 또는 Paket CLI를 사용하여 클라이언트 라이브러리 설치
PM> Install-Package Google.Cloud.BigQuery.V2 -Version 1.0.0-beta19
.NET CLI> dotnet add package Google.Cloud.BigQuery.V2 --version 1.0.0-beta19
Paket CLI> paket add Google.Cloud.BigQuery.V2 --version 1.0.0-beta19
2
Cloud Platform 콘솔 프로젝트 설정
  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. Set up a GCP Console project.

    Set up a project

    Click to:

    • Create or select a project.
    • Enable the BigQuery API for that project.
    • Create a service account.
    • Download a private key as JSON.

    You can view and manage these resources at any time in the GCP Console.

  3. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the file path of the JSON file that contains your service account key. This variable only applies to your current shell session, so if you open a new session, set the variable again.

3
코드 작성
using System;
using Google.Cloud.BigQuery.V2;

namespace GoogleCloudSamples
{
    public class BigquerySample
    {
        const string usage = @"Usage:
BigquerySample <project_id>";

        private static void Main(string[] args)
        {
            string projectId = null;
            if (args.Length == 0)
            {
                Console.WriteLine(usage);
            }
            else
            {
                projectId = args[0];
                // By default, the Google.Cloud.BigQuery.V2 library client will authenticate
                // using the service account file (created in the Google Developers
                // Console) specified by the GOOGLE_APPLICATION_CREDENTIALS
                // environment variable. If you are running on
                // a Google Compute Engine VM, authentication is completely
                // automatic.
                var client = BigQueryClient.Create(projectId);
                string query = @"SELECT
                    CONCAT(
                        'https://stackoverflow.com/questions/',
                        CAST(id as STRING)) as url, view_count
                    FROM `bigquery-public-data.stackoverflow.posts_questions`
                    WHERE tags like '%google-bigquery%'
                    ORDER BY view_count DESC
                    LIMIT 10";
                var result = client.ExecuteQuery(query, parameters: null);
                Console.Write("\nQuery Results:\n------------\n");
                foreach (var row in result)
                {
                    Console.WriteLine($"{row["url"]}: {row["view_count"]} views");
                }
            }
            Console.WriteLine("\nPress any key...");
            Console.ReadKey();
        }
    }
}
Translation API를 통해 다양한 언어로 텍스트 번역
1
NuGet 패키지 관리자, .NET CLI 또는 Paket CLI를 사용하여 클라이언트 라이브러리 설치
PM>Install-Package Google.Cloud.Translation.V2 -Version 1.0.0
.NET CLI> dotnet add package Google.Cloud.Translation.V2 --version 1.0.0
Paket CLI> paket add Google.Cloud.Translation.V2 --version 1.0.0
2
Cloud Platform 콘솔 프로젝트 설정
  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. Set up a GCP Console project.

    Set up a project

    Click to:

    • Create or select a project.
    • Enable the Cloud Translation API for that project.
    • Create a service account.
    • Download a private key as JSON.

    You can view and manage these resources at any time in the GCP Console.

  3. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the file path of the JSON file that contains your service account key. This variable only applies to your current shell session, so if you open a new session, set the variable again.

3
코드 작성
using Google.Cloud.Translation.V2;
using System;

public class QuickStart
{
    public static void Main(string[] args)
    {
        Console.OutputEncoding = System.Text.Encoding.Unicode;
        TranslationClient client = TranslationClient.Create();
        var response = client.TranslateText("Hello World.", "ru");
        Console.WriteLine(response.TranslatedText);
    }
}
Vision API를 사용하여 이미지 분석
1
NuGet 패키지 관리자, .NET CLI 또는 Paket CLI를 사용하여 클라이언트 라이브러리 설치
PM> Install-Package Google.Cloud.Vision.V1 -Version 1.0.0
.NET CLI> dotnet add package Google.Cloud.Vision.V1 --version 1.0.0
Paket CLI> paket add Google.Cloud.Vision.V1 --version 1.0.0
2
Cloud Platform 콘솔 프로젝트 설정
  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. Set up a GCP Console project.

    Set up a project

    Click to:

    • Create or select a project.
    • Enable the Cloud Vision API for that project.
    • Create a service account.
    • Download a private key as JSON.

    You can view and manage these resources at any time in the GCP Console.

  3. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the file path of the JSON file that contains your service account key. This variable only applies to your current shell session, so if you open a new session, set the variable again.

3
코드 작성
using Google.Cloud.Vision.V1;
using System;

namespace GoogleCloudSamples
{
    public class QuickStart
    {
        public static void Main(string[] args)
        {
            // Instantiates a client
            var client = ImageAnnotatorClient.Create();
            // Load the image file into memory
            var image = Image.FromFile("wakeupcat.jpg");
            // Performs label detection on the image file
            var response = client.DetectLabels(image);
            foreach (var annotation in response)
            {
                if (annotation.Description != null)
                    Console.WriteLine(annotation.Description);
            }
        }
    }
}
.NET 빠른 시작
프로덕션 문제 발견 및 해결

Google Stackdriver는 강력한 로깅, 모니터링, 보고 기능을 제공합니다. 클라우드 기반 애플리케이션의 상태, 성능, 가용성에 대한 유용한 정보를 제공하므로, 프러덕션 문제를 보다 신속하게 찾고 해결할 수 있습니다.

자세히 알아보기
GCP 커뮤니티에서 .NET 알아보기

궁금한 점이나 의견이 있나요? 커뮤니티에 가입하여 질문하거나 Google Cloud Platform에서 .NET 제작을 지원하는 Google 전문가와 직접 채팅해 보세요.