1

I have below three projects, all are created using VS2022 and targeting .net 6.

  1. ExternalProject (.dll)
  2. InternalProject (.dll)
  3. TestProject (.exe)

ExternalProject contains a reference to the InternalProject, also I am creating NuGet package of ExternalProject using the below command

dotnet pack ExternalProject.csproj /p:NuspecFile=ExternalClass.nuspec

The content of ExternalClass.nuspec file is below

<?xml version="1.0"?>
<package >
  <metadata>
    <id>ExternalProject</id>
    <version>1.0.10</version>
    <title>ExternalProject</title>
    <authors>Ustad</authors>
    <owners>Ustad</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
  </metadata>
  <files>
    <file src="..\InternalProject\bin\Debug\net6.0\*.*" target="lib\net6.0" />
  </files>
</package>

The problem is, that InternalProject dll is not being added to the ExternalProject NuGet package. Not sure what I am missing here.

HasaniH
  • 8,232
  • 6
  • 41
  • 59
Ustad
  • 71
  • 5
  • Does this answer your question? [Include all dependencies using dotnet pack](https://stackoverflow.com/questions/40396161/include-all-dependencies-using-dotnet-pack) – HasaniH Apr 19 '22 at 17:56
  • I have gone thorough that post, but it is not working in my case – Ustad Apr 19 '22 at 18:13

2 Answers2

1

I got the solution, one should edit ExternalProject.csproj file and add below xml. Also add PrivateAssets="all" in the ProjectReference element.

<PropertyGroup>
    <TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);GetMyPackageFiles</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>

<Target Name="GetMyPackageFiles">
    <ItemGroup>
        <BuildOutputInPackage Include="$(OutputPath)InternalProject.dll">
        </BuildOutputInPackage>
    </ItemGroup>
</Target>
Ustad
  • 71
  • 5
0

Since the answer in my comment is one year older than the current documentation I'll include here.

According to the docs:

NuGet dependencies of the packed project are added to the .nuspec file, so they're properly resolved when the package is installed. If the packed project has references to other projects, the other projects are not included in the package. Currently, you must have a package per project if you have project-to-project dependencies.

I.e. just like the linked answer says, there's no official way to do it other than publishing a package per project. If that's not an option, you can use the work arounds described there.

HasaniH
  • 8,232
  • 6
  • 41
  • 59