Search code examples
c#.netnugetnuget-packagenuspec

NuGet - NU5131: References declared in the nuspec file are not being packaged


I'm trying to reference two .dll files in a nupkg. I've added the files as references in the nuspec file:

<references>
   <reference file="Project.Modules.ModuleA.dll" />
   <reference file="Project.Modules.ModuleB.dll" />
</references>

When i try to pack, i get the following warning and the package does not include the referenced files.

WARNING: NU5131: References were found in the nuspec, but some reference assemblies were not found in both the nuspec and ref folder. Add the following reference assemblies: - Add Project.Modules.ModuleA.dll to the ref/any/ directory - Add Project.Modules.ModuleB.dll to the ref/any/ directory

Where do i place the files in order to get the package to include the required files?


Solution

  • Since I was using .net core 3.1, turns out all I had to do was to make some tweaks in the project.csproj file of the nupkg. Here's what I did:

    Add an item group:

    <ItemGroup>
        <ProjectReference Include="..\..\Project.Modules.ModuleA.csproj" >
          <PrivateAssets>all</PrivateAssets>
          <ReferenceOutputAssembly>true</ReferenceOutputAssembly>
          <IncludeAssets>Project.Modules.ModuleA.dll</IncludeAssets>
        </ProjectReference>
        <ProjectReference Include="..\Project.Modules.ModuleB.csproj" >
          <PrivateAssets>all</PrivateAssets>
          <ReferenceOutputAssembly>true</ReferenceOutputAssembly>
          <IncludeAssets>Project.Modules.ModuleB.dll</IncludeAssets>
        </ProjectReference>
      </ItemGroup>
    

    Then add a target:

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

    And finally add this inside the PropertyGroup element:

    <TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
    

    Works like a charm for me