0
votes

I have an "old style" .NET framework project which includes nuget references and other project references. Now I switched to the PackageReference format (removed the packages.config). I want to create a NuGet package for my project. So I added a reference to the "NuGet.Build.Tasks.Pack" package and used the MSBUILD pack target. In the first place it looked everything as expected, the resulting package contains all my references and the corresponding NuGet references. Now I have the problem, that I use also a project to project reference:

<ProjectReference Include="..\Wrapper\MyWrapper\MyWrapper.csproj">
  <Project>{6b9a7dd0-b93f-3a5e-8fdf-99d0bf811652}</Project>
  <Name>MyWrapper</Name>
</ProjectReference>

Based on the nuget documentation - for this reference:

Project to project references are considered by default as nuget package references

But I want that this project reference is packaged into my package instead of a "nuget package reference". I found postings that using

PrivateAssets="all"

for the project reference could fix the problem, but adding this attribute to the project reference node does not change anything. Any help would be great!

1
(Note you don't need to add a reference to NuGet.Build.Tasks.Pack, and you don't need that Project GUID). Have a read through this threadcanton7
Hmm I think I still need this. The thread you are referring to is about SDK project. But I use an "old style" project as mentioned in the descriptionFranz Gsell
You said "Now I switched to the PackageReference format (removed the packages.config)" -- which sounded like you converted your project to be an SDK-style. Do you mean you're using some weird hybrid of an old-school csproj, but using some select bits of an SDK-style project in there? That sounds horiffic, please don't do that. Just convert to an SDK-style project outrightcanton7
@canton7 Why should I not do that. Even Visual Studio itself offers the "Migrate to PackageReference" option in the context menu for the packages.config and References node?Franz Gsell
@FranzGsell, any update about this issue?Mr Qian

1 Answers

1
votes

I think you have missed something. It is not enough that you set PrivateAssets="all" for the ProjectReference. And actually, nuget will not view the referenced project as a nuget dependency and also nuget will not pack its assembly dll into the nupkg. You need other nodes.

Try these guidances:

Assume all your lib projects are target to net framework 4.7.2.

1) add the PrivateAssets="all" on the xxx.csproj file of the main project.

<ProjectReference Include="..\Wrapper\MyWrapper\MyWrapper.csproj">
  <Project>{6b9a7dd0-b93f-3a5e-8fdf-99d0bf811652}</Project>
  <Name>MyWrapper</Name>
  <PrivateAssets>All</PrivateAssets>
</ProjectReference>

2) also add these node on the xxx.csproj file of the main project to pack the assembly dll into the nupkg:

<PropertyGroup>
        <TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
    </PropertyGroup>
    <Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
        <ItemGroup>
            <BuildOutputInPackage Include="@(ReferenceCopyLocalPaths-&gt;WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))" />
        </ItemGroup>
    </Target>

3) then use this command to pack the project:

msbuild -t:rebuild,pack -p:PackageOutputPath=xxx\xxx -p:Authors="xxx" -p:Version="x.x.x"

Note: In my side, the main project called Mod and it references a project called Mod1. When I finish the pack process, you can see these in the nupkg.

enter image description here

It packs the refeneced dll as a lib rather than a nuget package.