question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Referencing Swashbuckle.AspNetCore 5.0.0 in library with multiple targets

See original GitHub issue

VERSION:

5.0.0

STEPS TO REPRODUCE:

Create project with multiple targets, e.g.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>netstandard2.0;netcoreapp3.1</TargetFrameworks>
    <PackageId>Test</PackageId>
    <Platforms>AnyCPU;x64</Platforms>
  </PropertyGroup>

  <ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0" />
    <PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="5.0.0" />
  </ItemGroup>
</Project>

EXPECTED RESULT:

Project should compile

ACTUAL RESULT:

Compilation error: The target “GenerateOpenApiDocuments” does not exist in the project.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
krispennercommented, Apr 2, 2020

I’ve narrowed this down to the referenced package in Swashbuckle 5.x: https://github.com/dotnet/aspnetcore/tree/master/src/Tools/Extensions.ApiDescription.Server

Options listed here: https://github.com/dotnet/aspnetcore/blob/master/src/Tools/Extensions.ApiDescription.Server/src/build/Microsoft.Extensions.ApiDescription.Server.props

Just add this to your csproj file and it will disable trying to generate your swagger file:

    <PropertyGroup>
        <TargetFrameworks>netcoreapp3.1;netstandard2.0</TargetFrameworks>
        <OpenApiGenerateDocuments>false</OpenApiGenerateDocuments>
    </PropertyGroup>

Or you can disabled it on build events only:

    <PropertyGroup>
        <TargetFrameworks>netcoreapp3.1;netstandard2.0</TargetFrameworks>
        <OpenApiGenerateDocumentsOnBuild>false</OpenApiGenerateDocumentsOnBuild>
    </PropertyGroup>
1reaction
bigwheels490commented, Mar 26, 2020

I’ve run into this same issue. Interestingly enough, if I specify the target framework on the build command line like dotnet build <project> --framework netcoreapp3.1 for each target framework, the build succeeds. When it tries to build all target frameworks at once, it fails. However, that solution doesn’t work when building as part of the dotnet pack command.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swashbuckle.AspNetCore 5.0.0
Swagger tools for documenting APIs built on ASP.NET Core.
Read more >
Getting a build err when I do "dotnet run"
I am having problems Swashbuckle.AspNetCore version 5.0.0-rc2 as explained in this post "https://github.com/domaindrivendev/Swashbuckle.
Read more >
What's new in ASP.NET Core 5.0
Swashbuckle is a popular open-source NuGet package that emits OpenAPI documents dynamically. Swashbuckle does this by introspecting over the API ...
Read more >
Swashbuckle.AspNetCore
Swagger tools for documenting API's built on ASP.NET Core.
Read more >
Enriched Web API Documentation using Swagger/OpenAPI in ...
In this article, we will learn about Web API documentation , how we can automatically generate it in ASP .NET Core and how...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found