Reputation: 457
I'm upgrading a project to use .Net Core 3.1 from 2.2, and am struggling with getting my tools working.
I have this section in my .csproj file which generates a swagger.json file at publish time - it gets executed in our build pipeline and published as an artifact.
<ItemGroup>
<DotNetCliToolReference Include="Swashbuckle.AspNetCore.Cli" Version="5.2.1" />
</ItemGroup>
<Target Name="Swagger" AfterTargets="PrepareForPublish" DependsOnTargets="Build" Outputs="$(PublishDir)swagger.json">
<Exec Command="dotnet swagger tofile --output $(PublishDir)swagger.json $(OutputPath)\$(AssemblyName).dll v1" />
</Target>
But I'm getting these errors:
Package Swashbuckle.AspNetCore.Cli 5.2.1 is not compatible with netcoreapp2.2 (.NETCoreApp,Version=v2.2). Package Swashbuckle.AspNetCore.Cli 5.2.1 supports:
- netcoreapp2.1 (.NETCoreApp,Version=v2.1) / any
- netcoreapp3.0 (.NETCoreApp,Version=v3.0) / any
and:
Invalid project-package combination for Swashbuckle.AspNetCore.Cli 5.2.1. DotnetToolReference project style can only contain references of the DotnetTool type
The weird thing is that my project is using 3.1 - I did a ctrl+f on both "netcoreapp2.2" and "2.2" and couldn't find anywhere that was being specified. How can I force my CLI tool to use the correct .NET Core version?
Upvotes: 2
Views: 6534
Reputation: 397
I encountered the same problem, although I've been trying to use .Net 8 and version 6.7.0 of the Cli. Using MichaelBo's answer, together with Paulo Morgado's comment, fixed it for me. The resulting steps are:
dotnet new tool-manifest
. This will create the .config/dotnet-tools.json file under your project (note that this folder might be hidden in certain IDEs, at least in Rider).dotnet tool install Swashbuckle.AspNetCore.Cli --version major.minor.patch
(replace major.minor.patch with your desired version).The final .config/dotnet-tools.json file should look something like:
{
"version": 1,
"isRoot": true,
"tools": {
"swashbuckle.aspnetcore.cli": {
"version": "major.minor.patch",
"commands": [
"swagger"
]
}
}
}
And then, I could run the command by setting it up as follows, in my project file:
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="dotnet swagger tofile --output swagger.json $(TargetDir)\MyProject.dll v1" EnvironmentVariables="ASPNETCORE_ENVIRONMENT=Development" />
</Target>
(note that the command paths, environment variables, Target Name, and AfterTarget are the ones required for my case, and are not the same as in the original question, or the ones you might require)
Upvotes: 0
Reputation: 727
I had the same issue when trying to use dotnet swagger
. I switched to using just swagger
and that fixed the issue. And as @Mike said, remove the ItemGroup from the project file and install the cli globally as outlined here: https://github.com/domaindrivendev/Swashbuckle.AspNetCore#retrieve-swagger-directly-from-a-startup-assembly
Upvotes: 1
Reputation: 21
I had the same problem and resolved it by following the installation steps described here: https://github.com/domaindrivendev/Swashbuckle.AspNetCore#retrieve-swagger-directly-from-a-startup-assembly, and by removing the ItemGroup of the project file:
<ItemGroup>
<DotNetCliToolReference Include="Swashbuckle.AspNetCore.Cli" Version="5.2.1" />
</ItemGroup>
Upvotes: 2