Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 556
Carsten Gehling Avatar asked Mar 07 '20 09:03

Carsten Gehling


People also ask

How do I create a NuGet package?

NuGet Package ManagerSelect Project > Manage NuGet Packages. In the NuGet Package Manager page, choose nuget.org as the Package source. From the Browse tab, search for Newtonsoft.Json, select Newtonsoft.Json in the list, and then select Install. If you're prompted to verify the installation, select OK.


1 Answers

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>
like image 152
zivkan Avatar answered Oct 07 '22 10:10

zivkan