Specifying separate App.config for client library - jimper/googleads-dotnet-lib GitHub Wiki

Introduction

By default, the Ads API .NET library gets its configuration from the application's App.config / Web.config. However, if you don't want to get your App.config cluttered, you could move the library-specific configuration into its own configuration file using the configSource property.

Step 1: Specify a configSource in your App.config

Modify your App.config to look like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="AdWordsApi" 
         type="System.Configuration.DictionarySectionHandler"/>
  </configSections>
  <AdWordsApi configSource="AdWordsApi.config"/>
…
</configuration>

The section name and the configSource depends on the API for which you are specifying configSource.

  • For AdWords and AdxBuyer APIs, it should be AdWordsApi and AdWordsApi.config respectively.
  • For DFP API, it should be DfpApi and DfpApi.config respectively.

Step 2: Specify the contents of your config file

Now create another config file with the name you specified on configSource, and move the configuration node from your App.config into this file, as follows:

<?xml version="1.0" encoding="utf-8" ?>
<AdWordsApi>
  … More settings 
</AdWordsApi>

The configuration node you move depends on the API for which you are specifying configSource.

  • For AdWords and AdxBuyer APIs, the node to move is AdWordsApi.
  • For DFP API, the node to move is DfpApi.

Step 3: Fix the build rules in your csproj

Finally, include new configuration file in your project. Change the properties of this file to Always copy to output folder.

Now build and run your project. Your application will start picking up values from the new configuration file.

⚠️ **GitHub.com Fallback** ⚠️