Swashbuckle.AspNetCore: "dotnet swagger tofile" throws error in .net 8 with Swashbuckle v6.4 or 6.5 - says compatibility issue
I’m trying to generate swagger in postbuildevents, to do that I tried installing Swashbuckle CLI. Project config: dotnet --version: 8.0.101 Swashbuckle.Aspnetcore version: 6.4.0 Swashbuckle.Aspnetcore.Cli --> install fails saying:
Package ‘Swashbuckle.AspNetCore.Cli 6.4.0’ has a package type ‘DotnetTool’ that is not supported by project ‘src\API’. and Package Swashbuckle.AspNetCore.Cli 6.4.0 is not compatible with net6.0 (.NETCoreApp,Version=v6.0). Package Swashbuckle.AspNetCore.Cli 6.4.0 supports:
- net5.0 (.NETCoreApp,Version=v5.0) / any
- net6.0 (.NETCoreApp,Version=v6.0) / any
- netcoreapp2.1 (.NETCoreApp,Version=v2.1) / any
- netcoreapp3.0 (.NETCoreApp,Version=v3.0) / any
Same issue popped when I updated the version to 6.5.0.
Also, if I don’t do this via CMD and implement it in my csproj script like this:
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="dotnet tool restore"></Exec>
<Exec Command="dotnet swagger tofile --output swagger_v1.json $(OutputPath)\$(AssemblyName).dll v1" />
</Target>
It throws this error [which is not helpful at all]:
MSB3073 The command “dotnet swagger tofile --output swagger_v1.json bin\Debug\net6.0\TestSwaggerGen.dll v1” exited with code 1.
And as per Nuget’s website, I can see that Swashbuckle CLI supports .net 8 but why does it say while installing the nuget package that .net 8 is not supported?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 19 (2 by maintainers)
Is a major release planned to fix this issue?
We will be adding
net8.0support in a forthcoming release.This is because the tool is compiled for .NET 7. You can fix it with
DOTNET_ROLL_FORWARD=LatestMajor:Hope this helps!
DotSwashbuckle targets only .NET 8
It would be nice if a version was released that also targeted .net 8, currently my pipelines have to install both 7 and 8.
Confirming adding
ENV DOTNET_ROLL_FORWARD=LatestMajorwhen running on dockermcr.microsoft.com/dotnet/sdk:8.0worked for me.Hi @desjoerd, I’ve tried this approach already as discussed in this Github issue still it seems like swagger tofile keeps on looking for .Net version 7.0.0. Upon installing Swagger CLI from Nuget, it throws error saying it’s not compatible with .Net 8/any.
Upon having a closer look at my output window (where I enabled debug mode in build properties), I noticed the following error response (entire stack trace): 1> Task “Exec” 1> Task Parameter:EnvironmentVariables=DOTNET_ROLL_FORWARD=LatestMajor 1> Task Parameter:Command=dotnet tool run swagger tofile --output swagger_patientv1.json bin\Debug\net8.0\X.API.dll patient 1> Environment Variables passed to tool: 1> DOTNET_ROLL_FORWARD=LatestMajor 1> dotnet tool run swagger tofile --output swagger_patientv1.json bin\Debug\net8.0\X.API.dll patient
1> C:\S2\repo\API\src\API\X.API\X.API.csproj(50,3): error MSB3073: The command “dotnet tool run swagger tofile --output swagger_patientv1.json bin\Debug\net8.0\X.API.dll patient” exited with code -532462766.