I started off by reading through this suggested question similar to mine, but there was no resolution: Why does MSTest.TestAdapter adds its DLLs into my NuGet package?
Quick Problem Description
I wrote a NuGet package, and each time I install it, NUnit and NUnit3TestAdapter .dll's get added to the project I installed on. I want to find a solution that fixes this issue.
Repro steps
I have pushed two git repositories that reproduce the issue I am describing.
ClientLibrary / MainFramework (project from which I generated NuGet package) - https://github.com/harbourc/client-library-repro-nuget-issue
TargetProject (project that package is to be installed on) - https://github.com/harbourc/target-project-repro-nuget-issue
You can clone both repositories, restore their NuGet packages, and reproduce the issue as follows:
Locate ClientLibrary.1.0.0.nupkg in client-library-repro-nuget-issue/ClientLibrary/
Open package manager console for target-project-repro-nuget-issue and run
Install-Package C:\Path\To\client-library-repro-nuget-issue\ClientLibrary\ClientLibrary.1.0.0.nupkg
- Note the
NUnitandNUnit3TestAdapter.dll's that are added intoTargetProject-- even thoughTargetProjectalready hasNUnitandNUnit3TestAdapterinstalled.
Longer Overview
I have created my own NuGet package for internal use, called ClientLibrary, and I am attempting to install it on to another project, called TargetProject. Here is a quick breakdown of the structure:
FullSolution.slnMainFramework.csprojClientLibrary.csproj-->.nupkggenerated from this
Separate project:
TargetProject.slnTargetProject.csproj--> install.nupkgonto this
ClientLibrary has a reference to MainFramework, and uses many methods from MainFramework.
When installing ClientLibrary.1.0.0.nupkg onto TargetProject, the following .dll's are getting added to TargetProject:
nunit.engine.api.dll
nunit.engine.dll
NUnit3.TestAdapter.dll
NUnit3.TestAdapter.pdb
If I delete these .dll's, everything works fine, because TargetProject already has those packages installed anyway. They are not necessary, it's just annoying to have to delete them when installing.
Here is how I am adding ClientLibrary NuGet package to TargetProject:
- Build
ClientLibraryandMainFrameworkprojects to generate their .dlls - Change directory into
ClientLibraryfolder and runnuget spec
.nuspec file is generated:
<?xml version="1.0"?>
<package >
<metadata>
<id>ClientLibrary</id>
<version>1.0</version>
<title>Client Library</title>
<authors>Myself</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Client library for interacting with my application.</description>
<dependencies>
<group targetFramework=".NETFramework4.7.2" />
</dependencies>
</metadata>
</package>
Run
nuget pack -IncludeReferencedProjects-- BecauseClientLibraryhas a dependency onMainFramework(and several other packages used byMainFramework)Navigate to
TargetProject, open Package Manager Console- Run
Install-Package C:\Path\To\ClientLibrary.1.0.0.nupkg
Installation runs successfully, and then those .dll's I am complaining about get added.
Problem:
MainFramework has NUnit and NUnit3TestAdapter NuGet packages installed. ClientLibrary does not. So, the .dll's seem to be added because they are installed on MainFramework, but NOT installed on ClientLibrary. (Remember, ClientLibrary references MainFramework.dll.)
There are other packages installed on both MainFramework and ClientLibrary, and these do not have .dll's that get added to TargetProject upon installation, so I am assuming issue is caused by having packages present in MainFramework but NOT in ClientLibrary.
I believe I can "fix" this issue by installing NUnit and NUnit3TestAdapter onto ClientLibrary, but ClientLibrary doesn't actually use those packages at all, so it seems unnecessary.
How can I install ClientLibrary onto TargetProject without including the NUnit and NUnit3TestAdapter .dll's, and without having to install NUnit and NUnit3TestAdapter onto ClientLibrary? If possible, I would like to tell ClientLibrary.1.0.0.nupkg to use the NUnit and NUnit3TestAdapter packages that are already installed on TargetProject.
If the answer is "Not possible", that is fine, but I would like an explanation -- my overall goal for this question is to gain a better understanding of how NuGet and dependencies work, and understand why this has been an issue in the first place. Thank you for reading.

ClientLibraryonly uses some parts ofMainFramework, soMainFrameworkcan certainly be split intoMainFramework.FrameworkandMainFramework.Test, where theNUnitdependencies only exist inMainFramework.Test, andClientLibraryonly utilizesMainFramework.Framework. Thank for the analysis. - Christine