Google Cloud Libraries for .NET
repository·main·Indexed 22 days ago
https://github.com/googleapis/google-cloud-dotnetIdiomatic .NET client libraries for Google Cloud Platform services, providing NuGet packages for various APIs including BigQuery, Cloud Logging, Cloud Storage, Compute Engine, and Vertex AI. The repository includes tools for running benchmarks, integration testing, and a console formatter for ASP.NET Core logging.
What's inside google-cloud-dotnet
- Google Cloud Libraries for .NET provide idiomatic client libraries for interacting with Google Cloud Platform services within the .NET ecosystem. These libraries are designed to follow .NET patterns and best practices, making it easier for developers to integrate Google Cloud services into their applications.
Getting started with Google.Cloud.BigQuery.V2
mainTheGoogle.Cloud.BigQuery.V2library is a high-level wrapper around theGoogle.Apis.Bigquery.v2generated library. Most common operations are performed using theBigQueryClientclass. Additional wrapper classes are provided to simplify interactions with datasets, tables, and query results.Getting started with Google Cloud Datastore for .NET
mainTo work with Google Cloud Datastore in .NET, use the
DatastoreDbclass.DatastoreDbacts as a high-level wrapper aroundDatastoreClient, simplifying operations by assuming all actions occur on the same partition and providing built-in support for page streaming on structured query results.For a full introduction with runnable code samples, refer to the Datastore Quickstart.
Getting started with Google Cloud Translation V2
mainThe
Google.Cloud.Translation.V2library provides a high-level wrapper around theGoogle.Apis.Translate.v2generated library. It simplifies translation tasks through two primary client classes:TranslationClient: For standard translation operations.AdvancedTranslationClient: For more advanced features or specific model requirements.
Authentication is primarily handled via OAuth2, though API key authentication is supported for migration purposes.
Use Google.Cloud.Logging.Console for ASP.NET Core logging
mainGoogle.Cloud.Logging.Consoleis a console formatter that outputs log entries as JSON using the schema expected by Google Cloud Logging. It is designed to be a lightweight, non-invasive way to integrate logging when running ASP.NET Core (or any framework usingMicrosoft.Extensions.Logging) on Google Cloud Platform. By using this formatter, your console logs are automatically parsed into structured logs in Google Cloud Logging.Available Google Cloud .NET Packages
mainThe following NuGet packages are available for use in .NET projects. You can find the latest versions and documentation via the provided links.
| Package | Latest version | Description | |---------|----------------|-------------| | [Google.Test.V1](https://googleapis.dev/dotnet/Google.Test.V1/latest) | [](https://nuget.org/packages/Google.Test.V1) | [Test Product](https://google.com) | | [Google.Test.V2](https://googleapis.dev/dotnet/Google.Test.V2/latest) | [](https://nuget.org/packages/Google.Test.V2) | [Test Product 2](https://google.com) |Integrate Google Cloud Logging with log4net
mainGoogle.Cloud.Logging.Log4Netis a .NET client library that allows you to integrate Google Cloud Logging with the log4net logging framework. It uses theGoogleStackdriverAppenderto send logs to Google Cloud.Handle timestamp projections in Datastore queries
mainWhen performing a query that includes a projection, any timestamp fields are returned as integer values. To correctly convert these back into usable .NET types, use the following conversion methods on the
Valueobject:Value.ToDateTimeFromProjection(): Converts integer or timestamp values toDateTime.Value.ToDateTimeOffsetFromProjection(): Converts integer or timestamp values toDateTimeOffset.
Manage the lifecycle of Translation clients
mainWhen using
TranslationClientorAdvancedTranslationClient, it is highly recommended to reuse a single client object throughout your application's lifecycle.While you can create clients frequently, doing so can lead to issues with memory and network connection usage. If your architecture requires frequent creation of new client objects, ensure you explicitly dispose of them to facilitate timely resource clean-up.
Specify a field mask in Google Maps Places V1 requests
mainMany methods in the Google Maps Places V1 API require a field mask to determine which specific fields are returned in the response. This helps optimize performance and reduce payload size.
To specify a field mask in the .NET client library, you must include the mask in the
CallSettingsobject passed to the method call. To return all available fields, use the wildcard character*as the field mask value.// Example of using CallSettings to specify a field mask // Replace 'field_name_1,field_name_2' with the actual fields you want to retrieve var callSettings = new CallSettings { Header = new Dictionary<string, string> { { "x-goog-fieldmask", "field_name_1,field_name_2" } } }; // Use the callSettings when calling a method on the PlacesClient // var response = client.SomeMethod(request, callSettings);Identify BigQuery entities using References
mainThe canonical way to identify entities in the BigQuery API is through specific reference objects. This ensures type safety and consistency when performing operations. Common reference types include:
DatasetReferenceJobReferenceTableReferenceProjectReference
You can construct these references manually, via the
BigQueryClient, or through a parent entity (for example, usingBigQueryDataset.GetTableReferenceto get a reference to a table within that dataset).Platform support and .NET 4.5 compatibility
mainCurrent major versions of the Google Cloud client libraries have dropped support for.NET 4.5because the requiredMicrosoft.Bcl.AsyncInterfacesNuGet package does not support it. The libraries currently target.NET 4.6.1and.NET Standard 2.0.