Creating HoloLens applications is just cool! But connecting them to services in the Cloud makes it even cooler. Think of provisioning information on real-life objects or straw through Cloud data like persons, related contacts, documents and other stuff. This allows you to build rich applications containing information you normally process in a 2D world like your browsers. By extending it to a 3D world, you are able to process the data in a completely different way. Think of creating teams of people within your organization and group them based on specialties, getting a more clear inside view of your site structure in SharePoint or have a 3D model of the Microsoft Graph entities related objects.
This article is split into several posts which together describes how to connect your HoloLens App with the Microsoft Graph.
- Introduction
- Register, Connect and get data
- Reference your class library in Unity (this post)
- Create a scene in Unity and connect your library
Referencing a class library
In the previous post we wrote code to authenticate against Azure AD v2.0 endpoint and retrieved data from the Microsoft Graph inside our OfficeGraphLibrary Class Library.
We want to use this class library in our HoloLens application. It would be logical to reference the class library directly in the generated Visual Studio solutions by Unity. But that will give you issues when you try to compile.
NU1201 Project OfficeGraphLibrary is not compatible with uap10.0.10240 (UAP,Version=v10.0.10240). Project OfficeGraphLibrary supports: uap10.0.10586 (UAP,Version=v10.0.10586)
Unity allows you to use Universal Windows Platform specific plugins like out OfficeGraphLibrary class library. They will work when the plugin is only used for the Universal Windows Platform. If you also want to use the same plugin in the Unity Editor you will need to setup a placeholder. A placeholder is nothing more than a second plugin containing the same methods but only contains code which is allowed within the Unity Editor. Both plugins need to share the same name, assembly version and methods. How to accomplish this is explained here.
In our case we only want to have it work for the Universal Windows Platform.
Therefor we need to create a folder structure under assets where to store the class library and referencing dlls. The structure is as follow: Assets –> Plugins –> WSA. In that folder we need to copy the class library. You can do that by hand or use a Post-build event command line in the Build events settings page of the OfficeGraphLibrary class library. The command could be something like this:
copy /Y "$(TargetDir)\$(TargetName).dll" "c:\hololens\OfficeSketch\Assets\Plugins\WSA\$(TargetName).dll"
Unity will notice any changes made to files and folders within the Assets folder structure and updates when necessary. As soon as you focus the Unity application it updates.
Secondly we need to configure the settings of the asset in Unity. Click on the class library and make sure that the following settings are met.
Select the “WSAPlayer” as one of the platforms. You will get the second part containing the platform specific settings. Make sure that SDK is set to UWP , ScriptingBackend to Dot.Net and that the option Don’t process is selected. That last option only applies to managed assemblies and is only needed when for example your code contains classes which need to be serialized for Unity.
In our case we are also making use of the Newtonsoft.Json.dll library. This is because we have include the NuGet package names Microsoft.Graph which is depending on that library. Compiling the code will cause Unity to give an error.
ArgumentException: The Assembly Newtonsoft.Json is referenced by OfficeGraphLibrary (‘Assets/Plugins/WSA/OfficeGraphLibrary.dll’). But the dll is not allowed to be included or could not be found.
That means we need to add the Newtonsoft.json.dll library to the same folder in Unity with the same settings.
Now try to rebuild from Unity and you will notice it smoothly generates the Visual Studio solution for you. You will notice when you reload your solution in Visual Studio that the library references are included.
[…] Reference your class library in Unity […]
[…] Reference your class library in Unity […]
[…] Reference your class library in Unity […]
[…] Reference your class library in Unity […]
[…] Reference your class library in Unity […]
Hi,
Is this project available on github?
Hi, not yet.. but it will be in the near future