简体   繁体   中英

Swagger (Swashbuckle) on ASP.NET Core MVC targeting .Net Framework 4.6.1

I am migrating WebApi2 project to MVC6. As we have other dependencies written in .NET 4.6.1 we need to target same version.

"frameworks": {
"net461": {}}

I have added dependencies:

"Swashbuckle": "5.3.2",

But the problem is that there is no way to hook up/register it to the ASP.NET Core MVC.

Is there any way to do it?

With ASP.NET Core you should use the this port of Swashbuckle https://github.com/domaindrivendev/Ahoy

Than you will Add/Use extensions methods:

public void ConfigureServices(IServiceCollection services)
{
    ... Configure MVC services ...

    // Inject an implementation of ISwaggerProvider with defaulted   settings applied
    services.AddSwaggerGen();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    ... Enable MVC middleware ...

    // Enable middleware to serve generated Swagger as a JSON endpoint
    app.UseSwagger();

    // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.)
    app.UseSwaggerUi();
}

The 5.x version of Swashbuckle do not support ASP.NET Core MVC. You have to use the new Swashbuckle 6.x version which has support for ASP.NET Core.

The only version which supports ASP.NET Core 1.0 RTM is 6.0.0-beta901 .

So you need to add this to your project.json file

"Swashbuckle": "6.0.0-beta901"

The Swashbuckle version that is compatible with .Net Framework 4.6. is 5.6.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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