Actually I'm trying to use the two libraries Microsoft.Graph and Microsoft.Graph.Beta in parallel within my solution.
To get this to work, you can use aliases within references. For this purpose you first have to write within your .csproj
file something like this:
<PackageReference Include="Microsoft.Graph" Version="4.25.0" />
<PackageReference Include="Microsoft.Graph.Beta" Version="4.40.0-preview">
<Aliases>GraphBeta</Aliases>
</PackageReference>
After that within your .cs
file at the top you can write something like this:
extern alias GraphBeta;
using Beta = GraphBeta.Microsoft.Graph;
using Microsoft.Graph;
And within your code you can access both parts individually like this:
var client = new GraphServiceClient(new HttpClient());
var betaClient = new Beta.GraphServiceClient(new HttpClient());
So far so good.
Unfortunately within my solution I'm using the above code within a library project. This library project is referenced by my application project and within my application project I also need to make some calls to Microsoft.Graph
only. After adding the beta package to my library project I'm getting compiler errors from my application project like this:
error CS0433: The type 'IMessageAttachmentsCollectionPage' exists in both 'Microsoft.Graph.Beta, Version=4.40.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' and 'Microsoft.Graph, Version=4.25.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
So it seems, the given alias to the NuGet package within my library project doesn't flow upwards to my application project. My application project doesn't have any direct reference to any of the both Graph libraries, it just consumes it through the indirect dependency from the library project.
Also trying to add the extern alias
line to the file within my application project results in this error message:
error CS0430: The extern alias 'GraphBeta' was not specified in a /reference option
Any solution available to either make the alias flowing upwards to my application project or to make the Beta dependency internal to the library project?