danielwertheim

danielwertheim


notes from a passionate developer

Share


Sections


Tags


Disclaimer

This is a personal blog. The opinions expressed here represent my own and not those of my employer, nor current or previous. All content is published "as is", without warranty of any kind and I don't take any responsibility and can't be liable for any claims, damages or other liabilities that might be caused by the content.

How to create a NuGet metapackage

This is more of a note to myself post, but last week I had the need to create a metapackage (a package without any contents, one that just references other packages). It was a really long time ago since I did that 👴Like in the pre dotnet CLI age, where you manually created the .nuspec files. Can't be that hard, now, right? Nope. But there were issues.

The Goal is to, for an empty project (apart from references), be able to just run dotnet pack and get a NuPkg created, without any issues.

But basically, doing e.g

dotnet new classlib -n Labs.MyMetapackage

dotnet add Labs.MyMetapackage/ \
    package Microsoft.Extensions.Configuration.EnvironmentVariables

rm Labs.MyMetapackage/Class1.cs

dotnet pack Labs.MyMetapackage/ \
    -c Release \
    -o dist

Looks promising, right? Lets look at the package

☹️That's not what we wanted. Well, there's an easy fix. Use IncludeBuildOutput and (depending on contents of package) IncludeContentInPack and set them to false. Either via .csproj or via command line switches (more info here).

dotnet pack Labs.MyMetapackage/ \
    -c Release \
    -o dist \
    -p:IncludeBuildOutput=false \
    -p:IncludeContentInPack=false

☹️Meh! As I usually make use of TreatWarningsAsErrors:true in build pipelines, this would be no fun, even though the package looks OK

Fear not 🙂 we could just silence the warning using NoWarn for NU5128 (more info) or using NoPackageAnalysis (more info).

Success! 🥳Nothing "new", more or less just note for myself. But if it helped you, then that's just a bonus.

//Daniel

View Comments