C#C
C#7mo ago
James

NSwag client causes build to fail the first time

Simplified for explanation

ProjectA (nswag generated clients)

ProjectB (depends on Project A generated clients)

    <PropertyGroup>
        <RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
    </PropertyGroup>

    <Target Name="NSwag" AfterTargets="PostBuildEvent" Condition=" '$(Configuration)' == 'Debug' ">
        <Exec WorkingDirectory="$(ProjectDir)" EnvironmentVariables="ASPNETCORE_ENVIRONMENT=Development" Command="$(NSwagExe_Net90) run nswag.json /variables:Configuration=$(Configuration)" />
    </Target>


Generate the clients like this

But then when it gets to ProjectB it fails because the type or namespace from the generated does not exist.

If I build again it works fine.

If I manually build A then B its fine.
Was this page helpful?