i tried to configure aspnet api versioning as follow ASP.NET Core Versioned API Explorer
so i added following nuget packages
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="2.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="2.2.0" />
but compiler complain
Severity Code Description Project File Line Suppression State
Error CS1929 'IServiceCollection' does not contain a definition for 'AddVersionedApiExplorer' and the best extension method overload 'IServiceCollectionExtensions.AddVersionedApiExplorer(IMvcCoreBuilder, Action)' requires a receiver of type 'IMvcCoreBuilder'
on this line
services.AddVersionedApiExplorer( o => o.GroupNameFormat = "'v'VVV" );
have you removed AddVersionedApiExplorer method ? or any issue on my configuration ?
Thanks
In version 2.x.x, the setup is services.AddMvcCore().AddVersionedApiExplorer(), but in version 3.x.x+ it has the simplified form of services.AddVersionedApiExplorer(). Sorry about the confusion. I haven't had enough time to fully update the wiki to call out these differences.
@commonsensesoftware thanks for the info cheers
It seems like this issue is solved. I'll be going through the documentation thoroughly this week. Thanks.
Is there a way in 2.2.0 to do the equivalent of services.AddMvc().AddVersionedApiExplorer() (no Core)?
I don't think so, but what are you trying to achieve? services.AddMvc() always implicitly calls services.AddMvcCore() on your behalf. The point of having it hang off of AddMvcCore is to support scenarios where the entire MVC stack is not being used (e.g. no UI/APIs only). Starting in v3.0 (currently beta), the setup will simply be services.AddVersionedApiExplorer() and the required underlying services will be setup for you.
I was trying to change my app from .AddMvc() to .AddMvcCore() to use api explorer. When I did that, I started getting some json exceptions from an un-resolvable service. My off-the-cuff assumption is that the service was something that .AddMvcCore() doesn't add.
Essentially, I was just being lazy. I should use .AddMvcCore() and explicitly tack on any other services I need... I'll do that.
Thanks.
@commonsensesoftware I'm using an Asp.Net Core Web API that targets net472. I'm struggling to find the services.AddMvcCore().AddVersionedApiExplorer(). I'm using version nuget package 2.3.0, what am I missing?
Most helpful comment
In version 2.x.x, the setup is
services.AddMvcCore().AddVersionedApiExplorer(), but in version 3.x.x+ it has the simplified form ofservices.AddVersionedApiExplorer(). Sorry about the confusion. I haven't had enough time to fully update the wiki to call out these differences.