You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AuthenticationBuilder未包含Google定义,Facebook正常,找不到对应NuGet包

问题原因及解决办法

1. 缺失Google认证的NuGet包

你找不到对应包是因为搜错了关键词,ASP.NET Core的Google认证官方包名称是Microsoft.AspNetCore.Authentication.Google,直接在NuGet包管理器里搜这个完整名称就能找到。

也可以用.NET CLI命令快速安装:

dotnet add package Microsoft.AspNetCore.Authentication.Google

2. 代码冗余优化(可选但更规范)

你代码里重复调用了services.AddAuthentication(),虽然不影响功能,但完全没必要,建议合并成一次链式调用,让代码更简洁:

var builder = WebApplication.CreateBuilder(args);
var services = builder.Services;
var configuration = builder.Configuration;

services.AddAuthentication()
    .AddFacebook(facebookOptions =>
    {
        facebookOptions.AppId = "xxxxx";
        facebookOptions.AppSecret = "xxxxx";
    })
    .AddGoogle(googleOptions =>
    {
        googleOptions.ClientId = configuration["Authentication:Google:ClientId"];
        googleOptions.ClientSecret = configuration["Authentication:Google:ClientSecret"];
    });

3. 版本匹配注意事项

确保安装的包版本和你的.NET项目版本一致(比如.NET 6对应包的6.x版本,.NET 8对应8.x版本),NuGet会自动推荐适配的版本,直接选最新稳定版即可。

内容的提问来源于stack exchange,提问作者Armando Monteiro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 17:06:00