# Configure Office 365 API Projects for Distribution

### Summary ###
This page explains some steps developers should consider taking on their projects that leverage the Office 365 APIs prior to distributing them to other developers, their customers, or to source control systems such as Team Foundation Server, Git or Visual Studio Online.

Specifically this page will look at two steps:

- [Fixup Azure AD Graph Client NuGet Package Reference](#fixup-azure-ad-graph-client-nuget-package-reference)
- [Cleaning the `web.config` for app-specific details](#cleaning-the-webconfig-for-app-specific-details)


# Fixup Azure AD Graph Client NuGet Package Reference

All projects that leverage the Office 365 API SDKs by way of adding a connected service include a NuGet package that adds Office 365 & Azure AD references to the project created in Visual Studio. 

The NuGet package added to the project by the **Office 365 API Tools** in Visual Studio is not present in the NuGet package registry and therefore attempts to perform a NuGet package restore will fail because it cannot find a matching package.

## Understanding the Problem ##

The **Office 365 API Tools for Visual Studio 2013**, version 1.3.41104.1, adds multiple NuGet packages to projects as part of completing the Add Connected Service wizard. One package in particular presents a challenge: **Microsoft Azure Active Directory Graph Client Library**.

The way Visual Studio works is that it, or addins, typically contain a local copy of the NuGet package so developers do not always have to be connected to the internet to download the NuGet packages. The package that the tools include has an ID of **Microsoft.Azure.ActiveDirectory.GraphClient** & a version of **1.0.22**.

When projects are committed to source control, typically the packages are not included as part of the commit because they can add a lot of extra storage space demands and unnecessarily increase the size of a package when sharing it with other developers. Therefore one of the first tasks developers do after getting a copy of the project from source control is to run [NuGet package restore](http://docs.nuget.org/docs/reference/package-restore).

The challenge is that a package with the same ID & version does not exist in the NuGet package registry; there is no package with an ID of **Microsoft.Azure.ActiveDirectory.GraphClient** & a version of **1.0.22**. The package does exist in the NuGet package registry, **[Microsoft.Azure.ActiveDirectory.GraphClient](http://www.nuget.org/packages/Microsoft.Azure.ActiveDirectory.GraphClient)**, but under different versions.

## Fixing the Azure AD Graph Client NuGet Package Reference ##

Until the Office 365 API Tools for Visual Studio 2013 are updated to fix this issue, it is recommended to alter the project prior to committing to your source control system, regardless if you are using Team Foundation Server, Visual Studio Online, Git or any other solution.

After creating the project, look within the project's `packages.config` file and search for a package with an ID of **Microsoft.Azure.ActiveDirectory.GraphClient** & version of **1.0.22**. The safest way to update the project is to uninstall & then reinstall the package.

Open the **Package Manager Console** in Visual Studio and enter the following to uninstall the package:

  ````powershell
  PM> Uninstall-Package -Id Microsoft.Azure.ActiveDirectory.GraphClient
  ````

  > If the uninstall throws an error about not finding the package, simply remove the package reference from the `packages.config` file manually & save your changes.

Now, install the public version of the same NuGet package from the public registry:

  ````powershell
  PM> Install-Package -Id Microsoft.Azure.ActiveDirectory.GraphClient -Version 2.0.2
  ````

  > The above example references a specific version of the Azure AD graph client that is known to work with the Office 365 APIs. Future versions may work so omitting the `-Version` argument is optional.

[back to top](#configure-office-365-api-projects-for-distribution)

# Cleaning the `web.config` for App-Specific Details

The **Office 365 API Tools** for Visual Studio add the ability to create a new Azure AD application with the necessary permissions for the Office 365 APIs using the **Connected Service** wizard in Visual Studio. When completing the wizard, multiple entries and customizations are made to the project's `web.config` file.

These modifications include the following app settings:

- **ida:ClientID**: The unique ID of the application created in your Azure AD tenant.
- **ida:Password**: The Azure AD application's key that was generated by the Connected Service wizard.
- **ida:AuthorizationUri**: The endpoint used to authenticate with Azure AD.

The **ida:ClientID** and **ida:Password** are unique to the Azure AD app. Some development teams may elect for each developer to code against their own app, similar to how developers work against their own local development database. Therefore you can think of the the **ida:ClientID** and **ida:Password** similar to database connection strings. 

The next time a developer uses the Connected Service wizard to create a new Azure AD application of the project, the wizard will detect the **ida:CliendID** and try to connect to an application in the current user's Azure AD tenant. If a match is not found, the Connected Service wizard will throw an error.

Therefore, prior to committing the project to source control or before sharing with other developers, it is recommended to remove the values from the **ida:ClientID** & **ida:Password** app settings in the `web.config`.

[back to top](#configure-office-365-api-projects-for-distribution)

----------

### Related links ###
- [NuGet: App for SharePoint Web Toolkit](http://www.nuget.org/packages/AppForSharePointWebToolkit)
- [NuGet: Package Restore](http://docs.nuget.org/docs/reference/package-restore)
- [MSDN: Office 365 API Client Library NuGet Packages](http://msdn.microsoft.com/office/office365/HowTo/adding-service-to-your-Visual-Studio-project#O365NuGets)

### Applies to ###
-  Office 365 Multi Tenant (MT)
-  Office 365 Dedicated (D)

### Author
Andrew Connell - [@andrewconnell](https://twitter.com/andrewconnell)

### Version history ###
Version  | Date | Comments
---------| -----| --------
0.1  | December 31, 2014 | First draft


