DEV Community

Wallism
Wallism

Posted on • Edited on

generate swagger file from dll

To generate a swagger file from a dll you need to run a command like this:
dotnet swagger tofile --output "valid-file-path" "valid-dll-path" v1

To make that work there's a few steps to follow and few issues you might hit.

First, you need Swashbuckle.AspNetCore. Instructions to install are in the link, install the latest version globally, you may need a different, lower version depending on your project (I did).

To install a specific version for a project, go to the root of that project in a ps or cmd window. Do the following:

First, make sure you're running the correct version of dotnet sdk, see this post and follow through to the SO article for how to change the sdk dotnet cli uses.
Then install the correct version of Swashbuckle:
(ensure you are in your project root folder)
dotnet new tool-manifest
dotnet tool install --version 6.2.3 Swashbuckle.AspNetCore.Cli

You should see in the output of the the install command where the dotnet-tools.json files is, that was updated by the command. If you run dotnet swagger in any subfolder, it will use this version, not the globally installed version.

Note on version numbers

when you run
dotnet tool install --version 6.5.0 Swashbuckle.AspNetCore.Cli
ensure the version is the same as the nuget package version that is installed in your api project.
So be careful when choosing your version or you will see an error like this:

Could not load file or assembly 'Swashbuckle.AspNetCore.Swagger, Version=6.4.0.0, Culture=neutral, PublicKeyToken=62657d7474907593'. The located assembly's manifest definition does not match the assembly reference.

Top comments (1)

Collapse
 
nechama profile image
Nechama

I also tried it and failed on this error:
The specified runtimeconfig.json [obj/Debug/MY_PROJECT_NAME.runtimeconfig.json] does not exist

any help?