简体   繁体   English

是否可以在同一个应用程序中同时使用 Microsoft.Graph 和 Microsoft.Graph.Beta?

[英]Is it possible to use both Microsoft.Graph and Microsoft.Graph.Beta in the same app?

I'm writing some C# code targeting .NET 4.8, which needs to use Microsoft Graph.我正在编写一些针对 .NET 4.8 的 C# 代码,它需要使用 Microsoft Graph。 It works OK with Microsoft.Graph SDK (V1), however when I try to switch to Beta, I'm getting compilation errors like它与 Microsoft.Graph SDK (V1) 一起工作正常,但是当我尝试切换到 Beta 时,出现编译错误,例如

Error CS0433    The type 'GraphServiceClient' exists in both 'Microsoft.Graph.Beta, Version=0.29.0.0 <...>' and 'Microsoft.Graph, Version=1.19.0.0 <...>'

The reason being that one other nuget I'm using, namely SharePointPnPCoreOnline, unfortunately depends on Microsoft.Graph 1.19.原因是我正在使用的另一个 nuget,即 SharePointPnPCoreOnline,不幸的是取决于 Microsoft.Graph 1.19。

It would seem that there should be no problem using both assemblies, as - according to the current documentation ( https://docs.microsoft.com/en-us/graph/sdks/use-beta ) - Beta should use its own namespace:似乎使用这两个程序集应该没有问题,因为 - 根据当前文档( https://docs.microsoft.com/en-us/graph/sdks/use-beta ) - Beta 应该使用自己的命名空间:

using Microsoft.Graph.Beta;

Unfortunately it is wrong, both libraries share the same namespace Microsoft.Graph.不幸的是,这是错误的,两个库共享相同的命名空间 Microsoft.Graph。 The code above results in上面的代码导致

Error CS0234    The type or namespace name 'Beta' does not exist in the namespace 'Microsoft.Graph' (are you missing an assembly reference?)

I'm trying to use compiler options to resolve the assembly, but it's extremely convoluted under VS2019 - so far no luck.我正在尝试使用编译器选项来解析程序集,但它在 VS2019 下非常复杂 - 到目前为止还没有运气。

But I'm wondering why can't I find anything on this issue, I'm surely not the only one - can it be that I miss something obvious?但我想知道为什么我在这个问题上找不到任何东西,我肯定不是唯一的 - 难道我错过了一些明显的东西? Please help :)请帮忙 :)

Not sure if you solved this, but I solved this by adding an alias to Microsoft.Graph.Beta package.不确定你是否解决了这个问题,但我通过向 Microsoft.Graph.Beta 包添加别名解决了这个问题。 Then when referencing, add this to be able to reference your beta-endpoints or resources.然后在引用时,添加它以便能够引用您的 beta 端点或资源。 Change MSGraphBeta to whatever you added as an alias to your package.MSGraphBeta更改为您作为别名添加到包中的任何内容。

extern alias MSGraphBeta;
using GraphBeta = MSGraphBeta.Microsoft.Graph;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM