Open Closed

Help with NSWAG or similar C# client builder #10484


0
acmeware created

10.3 MVC .NetCore

After noticing that you use nswag for the angular side of things I ran successfull it to create a C# API using the tools while targeting the swagger.json url. However, because of the rate at which our application changes, I was hoping to generate the file and the client at every build, but I cannot work through errors with targeting the csproj file or the assembly. Any example of this is in the documentation below.

I was wondering if you had any success in performing this during build time rather than run time and if you have any advice.

https://github.com/RicoSuter/NSwag/wiki/NSwag.MSBuild

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

<Target Name="NSwag" AfterTargets="PostBuildEvent" Condition=" '$(Configuration)' == 'Debug' ">
  <Message Importance="High" Text="$(NSwagExe_Net50) run nswag.json /variables:Configuration=$(Configuration)" />

  <Exec WorkingDirectory="$(ProjectDir)" EnvironmentVariables="ASPNETCORE_ENVIRONMENT=Development" Command="$(NSwagExe_Net50) run nswag.json /variables:Configuration=$(Configuration)" />

  <Delete Files="$(ProjectDir)\obj\$(MSBuildProjectFile).NSwag.targets" /> <!-- This thingy trigger project rebuild -->
</Target>

3 Answer(s)
  • 0
    musa.demir created
    Support Team

    Hi @acmeware

    Is PowerTools what you need? (https://docs.aspnetzero.com/en/aspnet-core-angular/latest/Rapid-Application-Development) If not, can you please explain your needs more detailed?

  • 0
    acmeware created

    No. We use that already. What I am looking to do is to automatically create (code generate) a separate C# client (think console) but have it automatically generated from the swagger.json whenever the aspnetzero MVC app completes a build.

  • 0
    musa.demir created
    Support Team

    We do not have any support to generated c# clients. You can check that: https://github.com/RicoSuter/NSwag/wiki/CSharpClientGenerator