Setting Up a .NET Development Environment

This tutorial shows how to prepare your local machine for developing .NET and .NET core apps that run on Google Cloud Platform (GCP) and call GCP APIs.

Install a development environment

The recommended development environment for running the .NET tutorials and sample apps in this documentation is Visual Studio 2017 or Visual Studio Code.

Create a GCP project

Create a GCP project to run your apps. GCP projects form the basis for creating, enabling, and using all GCP services.

Authentication

During local development, your .NET app must authenticate itself in order to interact with GCP APIs. The following instructions describe how to create a service account key to authenticate your app. Apps can use this method to authenticate locally and when deployed to GCP. Read more about authentication, including how authentication is handled once your app is deployed.

Create a service account key for authentication

GCP Console

  1. In the GCP Console, go to the Create service account key page.

    Go to the Create Service Account Key page
  2. From the Service account drop-down list, select New service account.
  3. In the Service account name field, enter a name .
  4. From the Role drop-down list, select Project > Owner.

    Note: The Role field authorizes your service account to access resources. You can view and change this field later by using GCP Console. If you are developing a production app, specify more granular permissions than Project > Owner. For more information, see granting roles to service accounts.
  5. Click Create. A JSON file that contains your key downloads to your computer.

Command line

You can run the following commands using the Cloud SDK on your local machine, or within Cloud Shell.

  1. Create the service account. Replace [NAME] with your desired service account name.

    gcloud iam service-accounts create [NAME]
  2. Grant permissions to the service account. Replace [PROJECT_ID] with your project ID.

    gcloud projects add-iam-policy-binding [PROJECT_ID] --member "serviceAccount:[NAME]@[PROJECT_ID].iam.gserviceaccount.com" --role "roles/owner"
    Note: The Role field authorizes your service account to access resources. You can view and change this field later by using GCP Console. If you are developing a production app, specify more granular permissions than Project > Owner. For more information, see granting roles to service accounts.
  3. Generate the key file. Replace [FILE_NAME] with a name for the key file.

    gcloud iam service-accounts keys create [FILE_NAME].json --iam-account [NAME]@[PROJECT_ID].iam.gserviceaccount.com

Next, set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the path of the JSON key that was downloaded. In PowerShell, the commands are:

For this PowerShell session.

PS > $env:GOOGLE_APPLICATION_CREDENTIALS = "$env:USERPROFILE\Downloads\your-project-id-dea9fa230eae3.json"

For all processes created after this command.

PS > [Environment]::SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "$env:USERPROFILE\Downloads\your-project-id-dea9fa230eae3.json", "User")

(Optional) Install .NET tools and SDKs

Even though you can create and manage GCP resources via your web browser using the Google Cloud Platform Console, if you'd prefer to manage your GCP resources from within Visual Studio or from the command-line, you can consider installing the following tools:

  • Cloud SDK: The Cloud SDK is a command-line interface for GCP products and services.

  • Cloud Tools for Visual Studio: Cloud Tools for Visual Studio enables development in Visual Studio on GCP.

  • Cloud Tools for PowerShell: Cloud Tools for PowerShell is a set of cmdlets for Windows PowerShell that lets you manage GCP resources.

What's next

Was this page helpful? Let us know how we did:

Send feedback about...