Base solution for your next web application
Open Closed

Help with NSWAG or similar C# client builder #10484

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.


<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 -->

3 Answer(s)
  • 0
    musa.demir created

    Hi @acmeware

    Is PowerTools what you need? ( 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

    We do not have any support to generated c# clients. You can check that: