Search code examples
nuget.net-standard

Including referenced projects in NuGet package


I have the following project in my solution which I am trying to use to create a NuGet package:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>

    <PackageId>ExpressionTreeTestObjects</PackageId>
    <Authors>Zev Spitz</Authors>
    <Company />
    <Product>ExpressionTreeTestObjects</Product>
    <Description>A set of expression trees, and instances of other types from System.Linq.Expressions, for testing code against a variety of expression trees. The objects are generated by the C# compiler, by the VB.NET compiler, or using the factory methods at System.Linq.Expressions.Expression.</Description>
    <Copyright>Copyright (c) 2019 Zev Spitz</Copyright>
    <PackageLicenseExpression>MIT</PackageLicenseExpression>
    <PackageProjectUrl>https://github.com/zspitz/ExpressionTreeToString</PackageProjectUrl>
    <RepositoryUrl>https://github.com/zspitz/ExpressionTreeToString</RepositoryUrl>
    <RepositoryType>git</RepositoryType>
    <PackageTags>expression-tree code-generation visual-basic.net vb.net csharp test-data tostring</PackageTags>

    <IncludeBuildOutput>true</IncludeBuildOutput>
    <IncludeReferencedProjects>true</IncludeReferencedProjects>

  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\ExpressionTreeTestObjects.VB\TestObjects.VB.vbproj" />
    <ProjectReference Include="..\ExpressionTreeTestObjects\TestObjects.csproj" />
  </ItemGroup>

</Project>

Build and pack both seem to work. However, the .nupkg file doesn't seem to include the referenced DLLs.

How can I troubleshoot this? How can I resolve it?


Solution

  • I think the solution can be found here:

    <Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
      <ItemGroup>
        <BuildOutputInPackage Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))" />
      </ItemGroup>
    </Target>