AddVersionedApiExplorer not working in Asp.Versioning?

71 Views Asked by At

I am learning ASP.NET Core and encounter with the following compiler error CS1061 on AddVersionedApiExplorer:

enter image description here.

I am using the following at the beginning of my code:

using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Asp.Versioning;
using Asp.Versioning.ApiExplorer;
using Microsoft.OpenApi.Models;

I have also installed

Asp.Versioning.Mvc
Asp.Versioning.Mvc.ApiExplorer,

However, I still can't solve the error.

Can anyone help with this?

Thanks,

Phil

1

There are 1 best solutions below

2
Brando Zhang On BEST ANSWER

According to this github issue, the usage of the ApiExplorer is like below:

builder.Services.AddApiVersioning( ).AddApiExplorer(options => { 

    options.GroupNameFormat = "json";
    options.SubstituteApiVersionInUrl = true;
});