microsoft / hack-together

Hack Together: Microsoft Graph and .NET is a hackathon for .NET developers to learn Microsoft Graph and Microsoft 365.
MIT License
523 stars 85 forks source link

Question: Use v1.0 and beta endpoints in one project #67

Closed mmsharepoint closed 1 year ago

mmsharepoint commented 1 year ago

Just wanted to raise some more "discussions" here and ask a question (and give one answer how I handle myself).

Anyone using v1.0 AND beta endpoint together in the own project? How do you handle? Do you use the new published 5.0.0 Graph .NET SDK package which simplifies it a bit? Do you "mix" older <=4.54.0 beta and v1.0 package?

I'd like to use the 5.0.0 but cannot due to one bug exactly in the beta endpoint I want to use AND because I have a Teams project and there is still a dependency with TeamsFx and 4.54.0 So I decided (also always in the past when there was no 5.x.x) to mix with HttpClient. So (not only!) to fulfill the conditions of hack-together I make all my v1.0 calls with .NET SDK and only one call (beta) I make via REST and the HttpClient

Would love to hear your feedback. Concerns, different approaches and why? Helpful for you?

svrooij commented 1 year ago
  1. Install Microsoft.Graph.Beta and Microsoft.Graph
  2. Rename the namespace for the beta client
  3. Create two GraphServiceClient instances, (from different namespaces).

I guess with that you could do the following:

using Azure.Identity;
using Microsoft.Graph;
using Microsoft.Graph.Models;
// This is the trick, we rename the namespace
using Beta = Microsoft.Graph.Beta;

// And then you can create 2 clients in the same file
var graphClient = new GraphServiceClient(interactiveCredential, scopes );
var betaClient = new Beta.GraphServiceClient(interactiveCredential, scopes );
andrueastman commented 1 year ago

As the older 4.x.x version will have models and request builders with conflicting namespaces, The suggestion from @svrooij should work out. There also more similar instructions at the link below.

https://github.com/microsoftgraph/msgraph-beta-sdk-dotnet/tree/support/4.x#using-the-beta-client-along-with-the-v10-library