So you grab an Office 365 API related project from someone and do the typical NuGet package restore to get all the stuff you need to run the project… but you get hit with this error:
An error occurred while trying to restore packages. Unable to find version ‘1.0.22’ of package ‘Microsoft.Azure.ActiveDirectory.GraphClient’.
What the heck?!?!
I’ll explain the Why below, but first let me explain how you fix it:
packages.configfile and locate this package like I have here in this sample
Delete the line for the Microsoft.Azure.ActiveDirectory.GraphClient and save your changes. While it would be nice ot uninstall the package, you can’t… because it can’t be found.
Within the References in the project, found in the Solution Explorer tool window, locate the reference for Microsoft.Azure.ActiveDirectory.GraphClient and delete it.
Now, manually reinstall the package. For instance, if you did this using the Package Manager Console, you’d run the following command:
PM> Install-Package Microsoft.Azure.ActiveDirectory.GraphClient
Now if you do the full NuGet package restore, all is good and your code will work.
It’s requires me telling you a little story… sorry, no way around a story.
When you through the Add » Connected Service wizard as I show you in my walkthrough , one of the last things it does is add all the necessary NuGet packages. These NuGet packages are included with the Microsoft Office 365 API Tools version 1.3.41104.1 . Apparently one of the packages is the 1.0.22 version of the Azure AD Graph Client NuGet package referenced above.
The problem is that someone, presumably the Azure AD team, never got around to publishing this to the NuGet registry as you can see from the version history here: NuGet Registry: Microsoft.Azure.ActiveDirectory.GraphClient . This is the first time I’ve ever seen a non-existant non-private package missing form the public registry!
“But wait, my code still works when I create a new project!”
That’s right, that’s because you have a local cache of the package. But when someone else tries to use your project, because 99% of the developers out there don’t commit their package dependencies, they won’t have it.
Thankfully this is very easy to avoid. Until the Office Developer Tools for Visual Studio get updated to fix this known issue, here’s how you can avoid it.
Immediately after running through the Add » Connected Service dialog, I’d recommend you remove the graph client v1.0.22 and install the v2.0.2 version or the most current version. Do this by opening the Package Manager Console and running the two commands below:
Uninstall-Package Microsoft.Azure.ActiveDirectory.GraphClient Install-Package Microsoft.Azure.ActiveDirectory.GraphClient
Let’s say you want to share this project with someone else like publish it to GitHub where other developers will use their own Azure AD apps. In that case before you commit the project to source control or share it, I’d recommend you do the following:
- Clear the values for the ida:ClientID & ida:Password out of the
- Uninstall any Office 365 related NuGet packages from your project. Find all the packages by searching for Office365 in the
packages.configfile. Then uninstall all of them, one-by-one.
This way, the next time someone runs through the Connected Service wizard, it will add the NuGet packages, Azure AD app to your Azure AD tenant & all references to the project.