小编shi*_*997的帖子

“IServiceCollection”不包含“AddOcelot”的任何定义

我在使用 .NET Core 3.0 实现 Ocelot 时遇到问题,当我尝试在我的程序类中添加 ocelot(按照文档指定应该执行的操作)时,vs2019 显示了此错误:

“IServiceCollection”不包含“AddOcelot”的定义或接受“IServiceCollection”类型的第一个参数的可访问扩展方法“AddOcelot”(是否缺少任何使用指令或程序集引用?),

UseOcelot()方法也会重复此错误

public class Program
{
    public static void Main(string[] args)
    {
        new WebHostBuilder()
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .ConfigureAppConfiguration((context, config) => 
            {
                config
                    .SetBasePath(context.HostingEnvironment.ContentRootPath)
                    .AddJsonFile("appsettings.json", true, true)
                    .AddJsonFile($"appsettings.{context.HostingEnvironment.EnvironmentName}.json", true, true)
                    .AddJsonFile("ocelot.json")
                    .AddEnvironmentVariables();
            }).ConfigureServices(s => {
                s.AddOcelot().AddConsul();
            }).ConfigureLogging((hostingContext, logging) =>
            {
                logging.AddConsole();
            })
            .UseIIS()
            .Configure(app =>
            {
                app.UseOcelot().Wait();
            })
            .Build().Run();
    }
}
Run Code Online (Sandbox Code Playgroud)

我该怎么解决这个错误?,我已经安装了 Nuget 包 Ocelot 版本 13.8.0 和 Ocelot.Provider.Consul 版本 13.8.0。

c# api-gateway ocelot .net-core-3.0

1
推荐指数
1
解决办法
1552
查看次数

标签 统计

.net-core-3.0 ×1

api-gateway ×1

c# ×1

ocelot ×1