Getting started with Google Cloud Client Libraries for .NET

Posted by Mete Atamel, Developer Advocate

Last week, we introduced new tools and client libraries for .NET developers to integrate with Google Cloud Platform, including Google Cloud Client Libraries for .NET, a set of new client libraries that provide an idiomatic way for .NET developers to interact with GCP services. In this post, we’ll explain what it takes to install the new client libraries for .NET in your project.

Currently, the new client libraries support a subset of GCP services, including Google BigQuery, Google Cloud Pub/Sub and Google Cloud Storage (for other services, you still need to rely on the older Google API Client Libraries for .NET). Both sets of libraries can coexist in your project and as more services are supported by the new libraries, dependencies on the older libraries will diminish.

Authentication
As you would expect, the new client libraries are published on NuGet, the popular package manager for .NET, so it’s very easy to include them in your project. But before you can use them, you’ll need to set up authentication.

The GitHub page for the libraries (google-cloud-dotnet) describes the process for each different scenario in the authentication section. Briefly, to authenticate for local development and testing, install Cloud SDK for Windows, which comes with Google Cloud SDK shell, and use the gcloud command line tool to authenticate.

If you haven’t initialized gcloud yet, run the following command in Google Cloud SDK shell to initialize your project, zones and also setup authentication along the way:

$ gcloud init

If you’ve already set up gcloud and simply want to authenticate, run this command instead:

$ gcloud auth login

Installation

Now, let’s import and use the new libraries. Create a project in Visual Studio (but make sure it’s not a .NET Core project, as those are not supported by the libraries yet), right click on the project references and select “Manage NuGet packages”:

In NuGet window, select “Browse” and also check “Include prerelease.” The full list of supported services and their NuGet package names can be found on the google-cloud-dotnet page. Let’s install the library for Cloud Storage. For Cloud Storage, we need to search for Google.Storage:

The resulting list shows the new client library for Cloud Storage (Google.Storage) along with the low-level library (Google.Apis.Storage) that it depends on. Select Google.Storage and install it. When installation is complete, you’ll see Google.Storage as a reference, along with its Google.Apis dependencies:

That’s it! Now, you can use the new client library for Cloud Storage from your .NET application. If you’re looking for a sample, check out the Cloud Storage section of the GitHub page for the libraries.

Give it a try and let us know what you think. Any issues? Report them here. Better yet, help us improve our support for .NET applications by contributing.

“Interested in helping us improve the Google Cloud User Experience? Click here!”
Quelle: Google Cloud Platform

Published by