Closed dmitry-pavlov closed 2 years ago
My MSBuild target in MyNET5WebAPI project refers to nswag.json in MyNET5WebAPI.Clients project and looks like this:
<Target Name="NSwag" BeforeTargets="AfterBuild" Condition="'$(GenerateApiClient)'!='False' ">
<Exec Command="$(NSwagExe_Net50) run ../MyNET5WebAPI.Clients/nswag.json /variables:Configuration=$(Configuration) /runtime:Net50" />
</Target>
The root of the evil was the wrong value for aspNetCoreEnvironment
setting, which somehow was causing issues with resolving services from DI
. Once I set the right value (in my case environment name was 'LocalDevelopment') NSwag
MSBuild
target got fixed and started working OK.
"aspNetCoreEnvironment": "LocalDevelopment"
P.S. It is still confusing me as the reason is totally unclear (at least to me), but hope this helps someone else experiencing this "magic".
Closing the issue.
I am getting
No service for type 'Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider' has been registered
exception on MS Build post build event from NSwag target for unclear reason.The projects structure - 2 projects API and class library:
MyNET5WebAPI dir - .NET 5 Web API project with post build MS Build NSwag target MyNET5WebAPI.Clients dir - .NET 5 Class library project with nswag.json and where generated output goes
Re: error - I have tried adding to DI what errors states to Startup.ConfigureServices both way:
services.AddMvcCore().AddApiExplorer();
as wels as:
Questions:
IApiDescriptionGroupCollectionProvider
fromDI
- any pointers?IApiDescriptionGroupCollectionProvider
? I mean what in my API project is causing to require this dependency at all?The same setup used to work a week ago, I see no OpenApi related changes, but had recently updated to major 5 versions for most of the NuGet packages.
What am I missing? Any ideas are much appreciated.