Paket icon indicating copy to clipboard operation
Paket copied to clipboard

Pack nupkg and include all ProjectReferences as dependencies

Open nicholi opened this issue 3 years ago • 2 comments

Description

Attemping to build nupkgs for projects with other project references and want to include the references as a nuget dependency (not package the binary files). So that the referenced projects themselves can also be packaged as their own nupkg's. I believe the documentation states that all project references with paket.templates should be included as dependencies in the generated nuspec, but I can't seem to get it to work. I am assuming there is something I am missing in the setup or parameter usage. Unless this just isn't possible with paket.

Repro steps

I have compiled a simple set of shell commands to create the two project setup: Domain.csproj and Domain.Models.csproj. Domain depends on Domain.Models. I have also included the standard dotnet pack version, which references the other project correctly as a dependency in the resulting nuspec.

I could create a github repo of the sample if necessary as well.

# create sln and csprojs
mkdir sampleSln sampleSln/nupkgs
cd sampleSln
dotnet new sln
dotnet new classlib -n Domain
dotnet new classlib -n Domain.Models
dotnet sln add Domain
dotnet sln add Domain.Models

# add reference
dotnet add Domain/Domain.csproj reference Domain.Models/Domain.Models.csproj

# basic paket templates
tee Domain/Domain.csproj.paket.template <<< "type project"
tee Domain.Models/Domain.Models.csproj.paket.template <<< "type project"

# install paket
dotnet new tool-manifest
dotnet tool install paket
dotnet paket init

# give simple dependencies to each project
dotnet paket add -p Domain/Domain.csproj NLog
dotnet paket add -p Domain.Models/Domain.Models.csproj Newtonsoft.Json

# run paket basics
dotnet paket install
dotnet paket restore

# build Domain project
cd Domain
dotnet build -c Release

# attempt packaging
dotnet paket pack --version 1.0.0.1 ../nupkgs/paket/
dotnet pack -c Release -o ../nupkgs/dotnet/ -p:PackageVersion=1.0.0.1 Domain.csproj

Expected behavior

Expecting something close to the dotnet pack generated nuspec:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>
    <id>Domain</id>
    <version>1.0.0.1</version>
    <authors>Domain</authors>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Package Description</description>
    <dependencies>
      <group targetFramework="net6.0">
        <dependency id="Domain.Models" version="1.0.0.1" exclude="Build,Analyzers" />
      </group>
    </dependencies>
  </metadata>
</package>

We have the ProjectReference for Domain.Models as a dependency. Also this nupkg is only packaging Domain.dll in lib/. NOTE: its obviously missing the NLog dependency as it doesn't know anything about paket files, this isn't the issue here and correctly handled in paket's nuspec.

Actual behavior

But what we are getting from paket is:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
  <metadata>
    <id>Domain</id>
    <version>1.0.0.1</version>
    <title>Domain</title>
    <authors>Domain</authors>
    <description>Domain library.</description>
    <dependencies>
      <dependency id="NLog" version="0.0" />
    </dependencies>
  </metadata>
</package>

We have no dependency to Domain.Models here, and the nupkg is packaging both Domain.dll and Domain.Models.dll in lib/.

Using

dotnet: 6.0.300
paket: 7.1.5+e2fe7c693356a5e70a74cc01501f7dc5f8996695

Is there something else which needs to be added to the paket.templates? Or an additional parameter when running dotnet paket pack?

nicholi avatar May 17 '22 05:05 nicholi

Did you add a paket.template file in each project´s directory?

Flohack74 avatar Sep 12 '22 15:09 Flohack74

Yes paket.template in each directory, filled with only

type project

nicholi avatar Oct 01 '22 15:10 nicholi