.NET ON GOOGLE CLOUD PLATFORM

Try It Free View Documentation

Build, Deploy, Debug, and Monitor Highly Scalable .NET Apps

  • Build .NET apps using Visual Studio, browser based command-line, or Windows PowerShell
  • Use GCP services through idiomatic .NET libraries
  • Query fully-managed SQL databases using C#
  • Scale .NET Core apps using Google’s technology
  • Launch pre-configured ASP.NET Windows Servers
  • Deploy ASP.NET Core apps as Docker container
A Broad Set Of Idiomatic .NET Libraries

Take advantage of popular libraries in C# to access Google Cloud Platform services

Store & archive data within Cloud Storage
Access fully managed NoSQL database using C#
Perform data analysis with BigQuery
Translate text in different languages with the Translation API
Analyze images using the Vision API
Store & archive data within Cloud Storage
1
Install the client library using NuGet Package Manager, .NET CLI, or 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
Set up a Cloud Platform Console project
  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
Write your code
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);
            }
        }
    }
}
Access fully managed NoSQL database using C#
1
Install the client library using NuGet Package Manager, .NET CLI, or 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
Set up a Cloud Platform Console project
  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
Write your code
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"]}");
            }
        }
    }
}
Perform data analysis with BigQuery
1
Install the client library using NuGet Package Manager, .NET CLI, or 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
Set up a Cloud Platform Console project
  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
Write your code
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();
        }
    }
}
Translate text in different languages with the Translation API
1
Install the client library using NuGet Package Manager, .NET CLI, or 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
Set up a Cloud Platform Console project
  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
Write your code
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);
    }
}
Analyze images using the Vision API
1
Install the client library using NuGet Package Manager, .NET CLI, or 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
Set up a Cloud Platform Console project
  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
Write your code
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 QUICK STARTS
Find and Fix Production Issues

Google Stackdriver provides powerful logging, monitoring, and reporting capabilities. It equips you with insights into the health, performance, and availability of cloud-powered applications, enabling you to find and fix issues production faster.

Learn more
.NET ON GCP COMMUNITIES

Got something to say? Join our community to ask questions, or just chat with the experts at Google who help build the support for .NET on Google Cloud Platform.