-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
MSBuild
Package: NSwag.MSBuild
After installing the NSwag.MSBuild
NuGet package in your project, you can use the variable $(NSwagExe)
in your .csproj
file to run the NSwag command line tool in an MSBuild target. This way the tools can easily be updated via NuGet. The /controller
parameter can be omitted to generate a Swagger specification for all controllers.
<Target Name="NSwag" AfterTargets="Build">
<Exec Command="$(NSwagExe) webapi2swagger /assembly:$(OutDir)/MyWebAssembly.dll /controller:MyNamespace.MyController /output:swagger.json" />
<Exec Command="$(NSwagExe) swagger2tsclient /input:swagger.json /output:Scripts/MyController.ts" />
</Target>
TODO: Update wiki with this: https://github.com/RSuter/NSwag/issues/1159#issuecomment-363886104
For better testability, it is recommended to create an NSwag Configuration Document (e.g. with NSwagStudio) and use:
<Target Name="NSwag" AfterTargets="Build">
<Exec Command="$(NSwagExe) run nswag.json" />
</Target>
If you need to run the NSwag command line in x86 mode, use the $(NSwagExe_x86)
placeholder.
For .NET Core projects, one of the placeholders $(NSwagExe_Core##)
(e.g. $(NSwagExe_Core20)
for .NET Core 2.0) should be used instead of $(NSwagExe)
.
Available properties:
- NSwagExe
- NSwagExe_x86
- NSwagExe_Core10
- NSwagExe_Core11
- NSwagExe_Core20
- NSwagDir
- NSwagDir_Core10
- NSwagDir_Core11
- NSwagDir_Core20
See Command Line for more information.