Partially based on Hakan Fıstık [answer](https://stackoverflow.com/a/79230153/261604) and on Martin Capodici's comment on the question, here is my solution:
*Swashbuckle.AspNetCore* has reference to *Microsoft.Extensions.ApiDescription.Server* so all you have to do is to add these lines to the `.csproj` file's `PropertyGroup` block:
```
<OpenApiDocumentsDirectory>$(MSBuildProjectDirectory)\OUTPUT_FOLDER</OpenApiDocumentsDirectory>
<OpenApiGenerateDocuments>true</OpenApiGenerateDocuments>
<OpenApiGenerateDocumentsOnBuild>true</OpenApiGenerateDocumentsOnBuild>
```
This will generate the swagger json file in the `OUTPUT_FOLDER` with this name: `$(MSBuildProjectName).json`
More details:
<https://learn.microsoft.com/en-us/aspnet/core/fundamentals/openapi/overview?view=aspnetcore-9.0#microsoftextensionsapidescriptionserver-nuget-package>
I'm using *Swashbuckle.AspNetCore v6.6.2* and this is my solution:
*Swashbuckle.AspNetCore* has reference to *Microsoft.Extensions.ApiDescription.Server* so all you have to do is to add these lines to the `.csproj` file's `PropertyGroup` block:
```
<OpenApiDocumentsDirectory>$(MSBuildProjectDirectory)\OUTPUT_FOLDER</OpenApiDocumentsDirectory>
<OpenApiGenerateDocuments>true</OpenApiGenerateDocuments>
<OpenApiGenerateDocumentsOnBuild>true</OpenApiGenerateDocumentsOnBuild>
```
This will generate the swagger json file in the `OUTPUT_FOLDER` with this name: `$(MSBuildProjectName).json`
More details:
<https://learn.microsoft.com/en-us/aspnet/core/fundamentals/openapi/overview?view=aspnetcore-9.0#microsoftextensionsapidescriptionserver-nuget-package>