The .NET client library is [hosted on GitHub](https://github.com/googleads/google-ads-dotnet) and is distributed
as a [NuGet package](https://www.nuget.org/packages/Google.Ads.GoogleAds/). It offers several features to help you use
the API, including easier management of credentials and creation of Google Ads API
service clients.

The library supports the following .NET frameworks:

- .NET Framework 4.7.2 and later (`net472`)
- .NET Standard 2.1 (`netstandard2.1`)
- .NET 8.0 (`net8.0`)

.NET Standard 2.1 is compatible with several other .NET versions and
implementations, so the library might work fine on many other platforms.
However, we haven't officially tested the compatibility and thus don't
officially support these platforms. See the
[.NET Standard 2.1 documentation](https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-2-1#select-net-standard-version) to learn more.

The Google Ads API .NET library uses `Grpc.Net.Client` as the default transport layer,
with a fallback to `Grpc.Core` on unsupported platforms. While you can force the
use of `Grpc.Core` by setting `UseGrpcCore` to `true`, note that `Grpc.Core` is
deprecated and intended only for legacy maintenance. See the
[basic usage guide](https://developers.google.com/google-ads/api/docs/client-libs/dotnet/basic-usage#grpc-core) to learn more.

## Installation

Install the [`Google.Ads.GoogleAds` NuGet package](https://www.nuget.org/packages/Google.Ads.GoogleAds/) in your
project using the `dotnet` command-line tool:

    dotnet add package Google.Ads.GoogleAds

To load configuration settings from `appsettings.json`, `App.config`, or
environment variables, also install the
[`Google.Ads.GoogleAds.Extensions`](https://www.nuget.org/packages/Google.Ads.GoogleAds.Extensions/) package:

    dotnet add package Google.Ads.GoogleAds.Extensions

> [!NOTE]
> **Note:** Each `Google.Ads.GoogleAds` NuGet release supports specific Google Ads API versions. See the [supported API versions](https://developers.google.com/google-ads/api/docs/client-libs#supported-api-versions) table for version compatibility.

## Make your first API call

To use the Google Ads API, you need to perform several steps to get access to the API
and configure your Google Ads accounts. Follow the
[quick start guide](https://developers.google.com/google-ads/api/docs/get-started/make-first-call), which walks you
through all the important steps including setting up your Google Ads accounts.

## Basic usage

Initialize `GoogleAdsConfig` and `GoogleAdsClient` with your configuration
settings, retrieve `GoogleAdsServiceClient`, and stream campaign rows with
`SearchStream`:

    using System;
    using Google.Ads.Gax.Config;
    using Google.Ads.GoogleAds.Config;
    using Google.Ads.GoogleAds.Lib;
    using Google.Ads.GoogleAds.V26.Errors;
    using Google.Ads.GoogleAds.V26.Services;

    GoogleAdsConfig config = new GoogleAdsConfig()
    {
        OAuth2Mode = OAuth2Flow.APPLICATION,
        OAuth2ClientId = "INSERT_CLIENT_ID.apps.googleusercontent.com",
        OAuth2ClientSecret = "INSERT_CLIENT_SECRET",
        OAuth2RefreshToken = "INSERT_REFRESH_TOKEN",
        LoginCustomerId = "INSERT_LOGIN_CUSTOMER_ID_HERE"
    };

    GoogleAdsClient client = new GoogleAdsClient(config);
    GoogleAdsServiceClient googleAdsService =
        client.GetService(Services.V26.GoogleAdsService);

    string customerId = "INSERT_CUSTOMER_ID_HERE";
    string query =
        "SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id";

    try
    {
        googleAdsService.SearchStream(
            customerId,
            query,
            delegate (SearchGoogleAdsStreamResponse response)
            {
                foreach (GoogleAdsRow row in response.Results)
                {
                    Console.WriteLine(
                        $"Campaign ID {row.Campaign.Id}: {row.Campaign.Name}");
                }
            });
    }
    catch (GoogleAdsException ex)
    {
        Console.WriteLine($"Request ID {ex.RequestId} failed: {ex.Message}");
    }

Refer to the [basic usage guide](https://developers.google.com/google-ads/api/docs/client-libs/dotnet/basic-usage) to learn more about how to use the
.NET client library.

## Authorization and authentication

The .NET client library supports multiple approaches to authentication and
authorization, including OAuth 2.0 user credentials (for desktop and web
applications), service accounts, Application Default Credentials (`v24.1.0` and
later), and manual credential injection (`v27.0.0` and later). Refer to the
[authorization and authentication](https://developers.google.com/google-ads/api/docs/client-libs/dotnet/authentication) guide to learn more.

## Configuration and logging

The .NET client library supports multiple [configuration](https://developers.google.com/google-ads/api/docs/client-libs/dotnet/configuration)
and [logging](https://developers.google.com/google-ads/api/docs/client-libs/dotnet/logging) options using runtime objects, `appsettings.json`
or custom JSON files, environment variables, or `App.config` files. In case you
need to modify the logging behavior of the client library, refer to the
[custom gRPC interceptor guide](https://developers.google.com/google-ads/api/docs/client-libs/dotnet/custom-interceptors).

## Utilities

The .NET client library includes utility classes to improve API usability,
including media and video upload helpers (`UploadVideo` in `v27.2.0` and later).
Refer to the following guides to learn more:

- [FieldMasks](https://developers.google.com/google-ads/api/docs/client-libs/dotnet/field-masks)
- [ResourceNames](https://developers.google.com/google-ads/api/docs/client-libs/dotnet/resource-names)
- [Protocol buffer types](https://developers.google.com/google-ads/api/docs/client-libs/dotnet/working-with-protobuf)

## Fine-tune your application performance

Refer to the [performance tuning guide](https://developers.google.com/google-ads/api/docs/client-libs/dotnet/performance) for recommendations on how
to fine-tune your application's performance.