Create nuget package for multiple SDK projects

431 Views Asked by At

I have 3 .net standard SDK projects(Utils, Reporting and Testing) that I want to pack them into one nuget package called Shared and upload it in my local package management system to be able to be used in my other projects. I was thinking to use the csproj file(s) to fill all the package information so I don't have to use nuspec file(s). One way I tried is to create a new .net standard project called Shared that references all the first 3 projects and only fill the Shared.csproj.

<Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <TargetFramework>netstandard2.0</TargetFramework>
     <Copyright>Copyright (c) Me</Copyright>
     <GeneratePackageOnBuild>False</GeneratePackageOnBuild>
     <SkipCopyBuildProduct>true</SkipCopyBuildProduct>
     <GenerateDependencyFile>False</GenerateDependencyFile>
     <DebugSymbols>false</DebugSymbols>
     <DebugType>none</DebugType>
   </PropertyGroup>
   <ItemGroup>
     <ProjectReference Include="..\Utils.csproj" />
     <ProjectReference Include="..\Reporting.csproj" />
     <ProjectReference Include="..\Testing.csproj" />
   </ItemGroup>
</Project>

I've tried this msbuild command:

dotnet msbuild -t:pack=Shared.csproj;-p:Configuration=Release;PackageOutputPath=.\release;

and this nuget cli command:

nuget pack Shared.csproj -Build -IncludeReferencedProjects -Prop Configuration=Release

but they don't work. I'm not sure which one is more suited.

Are there more suited alternatives?

Later edit: I've added my code to github with @mu88's suggestion to not create a project only for grouping my other projects but I don't get the 3 projects in my nupkg's libs folder. Do I also specify each project in the dependencies.group section?

1

There are 1 best solutions below

6
mu88 On

I'd personally recommend using a .nuspec file - using a project only as a container to ship multiple assemblies together without any behavior at all doesn't seem right to me.
Such a .nuspec would look like this:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
    <metadata>
        <id>My.Package</id>
        <version>1.0.0</version>
        <description>My package</description>
        <authors>Me</authors>
        <dependencies>
            <group targetFramework="netstandard2.0" />
        </dependencies>
    </metadata>
    <files>
        <file src="*\bin\Debug\netstandard2.0\*.dll" target="lib\netstandard2.0" />
    </files>
</package>

And you have to call nuget pack .\.nuspec (using PowerShell).

The newer approach would be to not use .nuspec at all, but ship the three projects as three independent NuGet packages.