【发布时间】:2020-04-27 06:22:05
【问题描述】:
我在使用 .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();
}
}
我该如何解决这个错误?,我已经安装了 Nuget 包 Ocelot 版本 13.8.0 和 Ocelot.Provider.Consul 版本 13.8.0。
【问题讨论】:
-
确保包含必要的命名空间ocelot.readthedocs.io/en/latest/introduction/…
using Ocelot.DependencyInjection; using Ocelot.Middleware; -
下面提供的答案准确吗?
标签: c# .net-core-3.0 api-gateway ocelot