Carsten Gehling
Carsten Gehling

Reputation: 1248

How to create a nuget metapackage with the dotnet command?

I have a solution with a bunch of projects:

ProjectA.csproj
ProjectB.csproj
ProjectC.csproj

These are all individually packed as nuget packages:

dotnet pack ProjectA.csproj --version-suffix 1.0.0    ===> ProjectA-1.0.0.nupkg
dotnet pack ProjectB.csproj --version-suffix 1.0.0    ===> ProjectB-1.0.0.nupkg
dotnet pack ProjectC.csproj --version-suffix 1.0.0    ===> ProjectC-1.0.0.nupkg

Version number is automatically extracted by our build server with gitversion.exe

Now I would like to make a nuget metapackage, that automatically references all three nupkg's.

I could do this with a nuspec file, but then I would need to manually edit it, when our version number changes.

I could make a 4th project ProjectAll.csproj, that references the other three projects. But that would leave me with an empty DLL in the output of the applications using these packages.

What is the best way to proceed?

Upvotes: 6

Views: 753

Answers (1)

zivkan
zivkan

Reputation: 14981

I don't know if it's much of a "secret", but the dotnet CLI is, for most commands, just a wrapper for msbuild. This includes pack, meaning that NuGet's documentation on the MSBuild pack target is relevant. If you scroll down looking at each title, or simply search for the words "build output", you'll find the Output assemblies section. There it says:

IncludeBuildOutput: A boolean that determines whether the build output assemblies should be included in the package.

So, in your project file, you can have something like:

<Project Sdk="whatever. I can't be bothered looking it up and I haven't memorized it.">
  <PropertyGroup>
    <TargetFramework>same as your other projects. Most restrictive TFM if different projects have different TFMs</TargetFramework>
    <IncludeBuildOutput>false</IncludeBuildOutput>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\path\to\ProjectA.csproj" />
    <ProjectReference Include="..\path\to\ProjectB.csproj" />
    <ProjectReference Include="..\path\to\ProjectC.csproj" />
  <ItemGroup>
</Project>

Upvotes: 6

Related Questions