0

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?

Misi
  • 748
  • 5
  • 21
  • 46

1 Answers1

0

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.

mu88
  • 4,156
  • 1
  • 23
  • 47
  • So you would create only a .nuspec file directly in the solution? – Misi Jul 18 '22 at 13:38
  • Yes, exactly, that's what I would do – mu88 Jul 18 '22 at 13:42
  • Using this command `nuget pack Shared\Shared.nuspec -IncludeReferencedProjects -Prop Configuration=Release` it doesn't add anything in the lib folder from the nupkg. Do I have to specify them in the nuspec dependencies section? If so what is the format? – Misi Jul 18 '22 at 14:33
  • Did you build your solution before? If not, please update your question with your current version, folder structure, etc. (or provide it via GitHub repo). There should be no need to add additional parameters like `IncludeReferenceProjects`, etc. – mu88 Jul 18 '22 at 15:04
  • I've updated my question and added a git example. – Misi Jul 19 '22 at 16:30
  • Update line 16 in your `Shared.nuspec` to this: `` – mu88 Jul 20 '22 at 06:25