You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature : Allow project reference DLLs to be added to the parent nupkg for pack target like IncludeReferencedProjects in nuget.exe #3891
Make projectA have a ProjectReference to projectB.
Add <Type>project</Type> to the <ProjectReference>.
dotnet pack projectA
Open the resulting .nupkg's lib folder
Expected
projectB.dll should be in the .nupkg along with projectA.dll
Actual
projectB is still a package reference, not a DLL included in the package.
Environment
Tried latest dev's pack target.
dotnet --info
.NET Command Line Tools (1.0.0-preview3-004056)
Product Information:
Version: 1.0.0-preview3-004056
Commit SHA-1 hash: ccc4968bc3
Runtime Environment:
OS Name: Windows
OS Version: 10.0.14393
OS Platform: Windows
RID: win10-x64
UPDATE: Please see workaround posted as comment to see how to add ProjectReferences as DLLs in the package dynamically.
This is a non-trivial feature that hasn't been implemented for RC yet.
Supporting this will require potentially walking the entire project closure to determine all projects that need to be merged into the package, or reading the assets file and matching the project closure with both the project reference flags and the pack flags found in the project (since it can be set either way).
This is also impacted by build outputs not flowing transitively to parent projects yet.
I've gotten the setup that @ViktorHofer and @DomenPigeon have described setup and its works (thank you!). However one thing I have noticed is that if multiple frameworks are specified using TargetFrameworks then the ref folder does not seem to be populated. Is that happening for anyone else? If so has anyone managed to make this work with multiple frameworks?
Here's the updated version that work with multiple TargetFrameworks as well:
<ProjectSdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);IncludeProjectReferenceDlls</TargetsForTfmSpecificBuildOutput>
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);IncludeReferenceAssemblies</TargetsForTfmSpecificContentInPackage>
<NoWarn>$(NoWarn);NU5131</NoWarn>
</PropertyGroup>
<ItemGroup>
<ProjectReferenceInclude="..\ReferencedLibrary\ReferencedLibrary.csproj"PrivateAssets="all" />
</ItemGroup>
<TargetName="IncludeProjectReferenceDlls"DependsOnTargets="BuildOnlySettings;ResolveReferences">
<ItemGroup>
<BuildOutputInPackageInclude="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')->WithMetadataValue('PrivateAssets', 'all'))"TargetPath="%(ReferenceCopyLocalPaths.DestinationSubDirectory)" />
</ItemGroup>
</Target>
<!-- Add a ref folder to the package which only exposes the library so that the referenced class library doesn't get exposed. -->
<TargetName="IncludeReferenceAssemblies">
<ItemGroup>
<TfmSpecificPackageFileInclude="$(TargetPath)"PackagePath="ref/$(TargetFramework)" />
</ItemGroup>
</Target>
</Project>
Please share a minimal repro or a binlog. Hard to say without more data.
Sure, thanks for looking into this for me. This is the repo. WinFormsLibraryA is the entry project which
uses a nuget package Microsoft.Extensions.DependencyInjection
references project WinFormsLibraryB which uses another nuget package Microsoft.Extensions.Caching.Memory
Just open it in Visual Studio and pack the WinFormsLibraryA, then you will get this NU1012 issue.
The expected result is a nuget package that:
contains both WinFormsLibraryA and WinFormsLibraryB dll files inside the package
the nuspec file inside the package should have 2 PackageReference to both Microsoft.Extensions.DependencyInjection and Microsoft.Extensions.Caching.Memory
This should work similarly if the chain goes longer eg. I have a 3rd level project WinFormsLibraryC referenced by WinFormsLibraryB and has its own PackageReference
For others, I got asked about how to make the above work when using the dotnet pack --no-build switch. Basically the following:
call dotnet build
call task to sign assemblies using azure cert
call dotnet pack --no-build --no-restore
call task to sign packages using azure cert
Here's the updated sample that no works with --no-build:
<ProjectSdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);IncludeProjectReferenceDlls</TargetsForTfmSpecificBuildOutput>
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);IncludeReferenceAssemblies</TargetsForTfmSpecificContentInPackage>
<NoWarn>$(NoWarn);NU5131</NoWarn>
<BuildProjectReferencesCondition="'$(NoBuild)' == 'true'">false</BuildProjectReferences>
</PropertyGroup>
<ItemGroup>
<ProjectReferenceInclude="..\ReferencedLibrary\ReferencedLibrary.csproj"PrivateAssets="all" />
</ItemGroup>
<TargetName="IncludeProjectReferenceDlls"DependsOnTargets="BuildOnlySettings;ResolveReferences">
<ItemGroup>
<BuildOutputInPackageInclude="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')->WithMetadataValue('PrivateAssets', 'all'))"TargetPath="%(ReferenceCopyLocalPaths.DestinationSubDirectory)" />
</ItemGroup>
</Target>
<!-- Add a ref folder to the package which only exposes the library so that the referenced class library doesn't get exposed. -->
<TargetName="IncludeReferenceAssemblies">
<ItemGroup>
<TfmSpecificPackageFileInclude="$(TargetPath)"PackagePath="ref/$(TargetFramework)" />
</ItemGroup>
</Target>
</Project>
Make sure that when you invoke dotnet build and then dotnet pack, to use the same configuration. Ideally pass that in to both calls, i.e. in an CI environment:
Don't put pdbs into non symbol packages. Put pdbs into symbol packages when using IncludeSymbols=true
Put the documentation file .xml into the ref folder when using GenerateDocumentationFile=true
Put the compiler generated ref assembly into the ref folder instead of the full assembly. Reduces size and doesn't expose implementation details.
@afantyro sorry for my late reply - I couldn't get this to work without specifying exact platform versions. Also dependencies from transitive projects don't flow because of the use of PrivateAssets=all. See the README in the sample. I still hope this helps...
I have created nuget package successfully with few of the methods mentioned above, all my dll files are packed inside, but when i am trying to use that nuget package i get an error: NU1101: Unable to find package ReferencedPackageB. No packages exist with this id in source(s):
there is a ReferencedPackageB.dll inside
Seems like i was able to resolve this.
first issue was that my nuget packages were cached in %userprofile%\.nuget\packages and any changes i made werent reflected in the test app where i was inserting the nuget package.
second issue was obvious and mentioned in multiple examples, i needed the property PrivateAssets="All" which excludes the library from nuspec dependencies.
Activity
rrelyea commentedon Nov 8, 2016
Please check spec on wiki for planned behavior
joelverhagen commentedon Nov 8, 2016
Spec: https://github.com/NuGet/Home/wiki/Adding-nuget-pack-as-a-msbuild-target
This doesn't work:
The output .nuspec still has projectB as a package reference and only one file: projectA.dll under lib.
emgarten commentedon Nov 8, 2016
This is a non-trivial feature that hasn't been implemented for RC yet.
Supporting this will require potentially walking the entire project closure to determine all projects that need to be merged into the package, or reading the assets file and matching the project closure with both the project reference flags and the pack flags found in the project (since it can be set either way).
This is also impacted by build outputs not flowing transitively to parent projects yet.
joelverhagen commentedon Nov 10, 2016
Plan of action:
PackageSpecto the lock/assets file.<TreatAsPackageReference>is true.PackTaskaway from looking at child projects. Look at restore's assets file instead.This has repercussions on:
<Reference>. How is this collapsed?<PackageReference>... what about<Reference>?joelverhagen commentedon Dec 7, 2016
@rohit21agrawal, I partially got through consuming the assets file from in the pack task:
https://github.com/joelverhagen/NuGet.Client/tree/jver/3891
This also has some progress on getting the output DLLs of child projects (using
@(ReferenceCopyLocalPaths)MSBuild items).This branch is pretty rough so let me know if I can clarify.
rohit21agrawal commentedon Dec 9, 2016
As per @rrelyea : #3893 (comment)
"We don't plan to enable this in dotnet pack / msbuild /t:pack in 4.0 timeframe.
We'll listen to customer feedback and consider in the future."
448 remaining items
aetos382 commentedon Dec 6, 2024
I think the microsoft/CsWin32 repository will be helpful.
It contains a source generator that depends on the System.Text.Json package.
nathanmascitelli commentedon Dec 10, 2024
I've gotten the setup that @ViktorHofer and @DomenPigeon have described setup and its works (thank you!). However one thing I have noticed is that if multiple frameworks are specified using
TargetFrameworksthen thereffolder does not seem to be populated. Is that happening for anyone else? If so has anyone managed to make this work with multiple frameworks?antonioacg commentedon Dec 10, 2024
@nathanmascitelli I managed to do it using this as reference:
https://github.com/dotnet/machinelearning/blob/01c41644edef3d02060b4c8bb841878df3528050/eng/Packaging.targets#L19-L52
ViktorHofer commentedon Dec 10, 2024
Here's the updated version that work with multiple TargetFrameworks as well:
Hehe, that's my code copied from dotnet/runtime ;) I would not recommend using that here if not strictly necessary.
nathanmascitelli commentedon Dec 11, 2024
@antonioacg @ViktorHofer thank you both! Works like a charm.
afantyro commentedon Jan 6, 2025
anyone else getting this error with below solution?

ViktorHofer commentedon Jan 6, 2025
Please share a minimal repro or a binlog. Hard to say without more data.
afantyro commentedon Jan 7, 2025
Sure, thanks for looking into this for me. This is the repo.
WinFormsLibraryAis the entry project whichMicrosoft.Extensions.DependencyInjectionWinFormsLibraryBwhich uses another nuget packageMicrosoft.Extensions.Caching.MemoryJust open it in Visual Studio and pack the
WinFormsLibraryA, then you will get this NU1012 issue.The expected result is a nuget package that:
PackageReferenceto bothMicrosoft.Extensions.DependencyInjectionandMicrosoft.Extensions.Caching.MemoryThis should work similarly if the chain goes longer eg. I have a 3rd level project
WinFormsLibraryCreferenced byWinFormsLibraryBand has its ownPackageReferenceViktorHofer commentedon Apr 17, 2025
For others, I got asked about how to make the above work when using the
dotnet pack --no-buildswitch. Basically the following:Here's the updated sample that no works with
--no-build:Make sure that when you invoke
dotnet buildand thendotnet pack, to use the same configuration. Ideally pass that in to both calls, i.e. in an CI environment:dotnet build -c Release && dotnet pack --no-restore --no-build -c ReleaseThat's important because
dotnet packdefaults to Release whiledotnet builddefaults to Debug.ViktorHofer commentedon May 15, 2025
I finally published this sample into a GH repository: https://github.com/ViktorHofer/NuGetPackSamples/tree/main/samples/PackageWithRefAndAdditionalAssemblies
Updates:
IncludeSymbols=trueGenerateDocumentationFile=true@afantyro sorry for my late reply - I couldn't get this to work without specifying exact platform versions. Also dependencies from transitive projects don't flow because of the use of PrivateAssets=all. See the README in the sample. I still hope this helps...
testing workaround package
Added an snk and a strong name by TrabacchinLuigi & remove NuGet/Home…
taipignas commentedon Oct 22, 2025
I have created nuget package successfully with few of the methods mentioned above, all my dll files are packed inside, but when i am trying to use that nuget package i get an error:
NU1101: Unable to find package ReferencedPackageB. No packages exist with this id in source(s):there is a ReferencedPackageB.dll inside
Seems like i was able to resolve this.
%userprofile%\.nuget\packagesand any changes i made werent reflected in the test app where i was inserting the nuget package.PrivateAssets="All"which excludes the library from nuspec dependencies.Saibamen commentedon Apr 27, 2026
NuGet/NuGet.Client#7325