由于Startup.cs
文件中包含.AddMicrosoftGraph(Configuration.GetSection("GraphApi"))
,我的Startup.cs
文件中出现以下错误
Severity Code Description Project File Line Suppression State
Error CS1061 'MicrosoftIdentityAppCallsWebApiAuthenticationBuilder' does not contain a definition for 'AddMicrosoftGraph' and no accessible extension method 'AddMicrosoftGraph' accepting a first argument of type 'MicrosoftIdentityAppCallsWebApiAuthenticationBuilder' could be found (are you missing a using directive or an assembly reference?)
我有Microsoft.Graph
和Microsoft.Graph.Core
Nuget包添加到我的项目。
在我的Startup.cs
文件的顶部也有下面的using语句,尽管它们显然没有被使用。
using Microsoft.Graph;
using Microsoft.Graph.Core;
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpClient();
var scopes = new[] { "Files.ReadWrite.All " };
services
.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"))
// Add the possibility of acquiring a token to call a protected web API
.EnableTokenAcquisitionToCallDownstreamApi(scopes)
// Enables controllers and pages to get GraphServiceClient by dependency injection
// And use an in memory token cache
.AddMicrosoftGraph(Configuration.GetSection("GraphApi"))
.AddInMemoryTokenCaches();
}
我不确定是什么原因造成的。
需要引用命名空间Microsoft.Identity.Web
加using
using Microsoft.Graph;
using Microsoft.Graph.Core;
using Microsoft.Identity.Web;
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpClient();
var scopes = new[] { "Files.ReadWrite.All " };
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"))
// Add the possibility of acquiring a token to call a protected web API
.EnableTokenAcquisitionToCallDownstreamApi(scopes)
// Enables controllers and pages to get GraphServiceClient by dependency injection
// And use an in memory token cache
.AddMicrosoftGraph(Configuration.GetSection("GraphApi"))
.AddInMemoryTokenCaches();
}
资源:
MicrosoftGraphExtensions