Search code examples
asp.net-coreaspnet-api-versioning

AddVersionedApiExplorer not working in Asp.Versioning?


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


Solution

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

    builder.Services.AddApiVersioning( ).AddApiExplorer(options => { 
    
        options.GroupNameFormat = "json";
        options.SubstituteApiVersionInUrl = true;
    });