Search code examples
c#asp.net-core.net-corepackagenuget

C# library - Create NuGet package with Sdk type Microsoft.NET.Sdk.Web


I'm quite familiar with NuGet package generation, but this is the first time I'm trying to generate a package with a Microsoft.NET.Sdk.Web sdk type instead of the typical Microsoft.NET.Sdk.

I know this is probably uncommon, but I need this type of sdk to reference AspNetCore specific types (SignalR hubs) which are not available in the classic sdk format.

I always set these properties in my .csproj file to have the nuget package (.nupkg file) generated:

  1. PackageId
  2. Authors
  3. Company
  4. Version
  5. Target frameworks
  6. GeneratePackageOnBuild (true)
  7. GenerateDocumentationFile (true)
  8. DebugSymbols (true)
  9. DebugType (full)

Usually, this is enough to have my package properly created - but not with Microsoft.NET.Sdk.Web sdk format. I played a bit to create test scenarios and isolated the issue, I'm pretty sure this depends on the sdk format and not something else.

Expected behavior: .nupkg file generated in output directory (bin/Debug).

Actual behavior: Project builds but no .nupkg file is generated.

Has anyone already faced this issue?


Solution

  • Try changing back to the Microsoft.NET.Sdk and adding the FrameworkReference element:

    <ItemGroup>
        <FrameworkReference Include="Microsoft.AspNetCore.App" />
    </ItemGroup>
    

    See the Use ASP.NET Core APIs in a class library doc.