I have a c# project that creates a DLL and also creates a Nuget package in the release build.
This package is used in a plugin that has no direct reference from the EXE. This plugin is loaded dynamically.
Both the plugin and the EXE are located in a solution and build in the same target directory.
If only the plugin has a reference to the Nuget package, the corresponding DLL is not copied to the target directory. As soon as the EXE itself receives a reference to the Nuget package, the dependency is copied cleanly to the target directory.
How do I also force the plugin to copy the dependencies to the target directory?
If a direct reference or a transitive reference from EXE to the used package exists the dll is copied to the target directory.
CSPROJ of the Nuget package:
<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>net80-windows</TargetFramework><AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath><Product>PkgA</Product><LangVersion>latest</LangVersion><UseWindowsForms>true</UseWindowsForms><ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable><Configurations>Debug;Release</Configurations></PropertyGroup><PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"><OutputPath>$(SolutionDir)bin\$(Configuration)</OutputPath></PropertyGroup><PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"><OutputPath>$(SolutionDir)bin\$(Configuration)</OutputPath><Optimize>true</Optimize></PropertyGroup><PropertyGroup Condition="'$(Configuration)'=='Release'"><GeneratePackageOnBuild>True</GeneratePackageOnBuild></PropertyGroup><PropertyGroup><RestoreProjectStyle>PackageReference</RestoreProjectStyle><AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects><GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType></PropertyGroup><ItemGroup Label="NuGetFileToCopy"><Content Include=".build\**" PackagePath="build\" /><Content Include=".build\**" PackagePath="buildTransitive\" /><Content Include="$(SolutionDir)\bin\$(Configuration)\net80-windows\$(Product).pdb" PackagePath="contentFiles\any\net8.0-windows7.0" PackageCopyToOutput="false" Visible="false" /><Content Include="$(SolutionDir)\bin\$(Configuration)\net80-windows\$(Product).xml" PackagePath="contentFiles\any\net8.0-windows7.0" PackageCopyToOutput="false" Visible="false" /></ItemGroup></Project>
CSPROJ of the consuming Plugin:
<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>net80-windows</TargetFramework><AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath><UseWindowsForms>true</UseWindowsForms><ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable><Configurations>Debug;Release</Configurations></PropertyGroup><PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"><OutputPath>$(SolutionDir)bin\$(Configuration)</OutputPath></PropertyGroup><PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"><OutputPath>$(SolutionDir)bin\$(Configuration)</OutputPath><Optimize>true</Optimize></PropertyGroup><ItemGroup><PackageReference Include="PkgA" Version="0.*" /><PackageReference Include="System.ComponentModel.Annotations" Version="5.0.*" /><PackageReference Include="System.ComponentModel.Composition" Version="8.*" /></ItemGroup><ItemGroup><ProjectReference Include="..\Contracts\Contracts.csproj" /></ItemGroup><PropertyGroup><RestoreProjectStyle>PackageReference</RestoreProjectStyle><AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects><GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType></PropertyGroup></Project>
There is also a targets
file for the Nuget package, which copies the PDB and XML to the target directory. These files are correctly copied to the target directory.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><!-- copy the files to the output directory --><ItemGroup><_PkgANet80Files Include="$(MSBuildThisFileDirectory)..\..\contentFiles\any\net8.0-windows7.0\*.*" /><!-- include everything --><Content Include="@(_PkgANet80Files)"><Link>%(Filename)%(Extension)</Link><Visible>False</Visible><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory><Pack>False</Pack></Content></ItemGroup></Project>
The created nuspec
-file is:
<?xml version="1.0" encoding="utf-8"?><package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"><metadata><id>PkgA</id><version>0.0.1.7</version><authors>PkgA</authors><description>Package Description</description><repository type="git" commit="ad93ea6a6fa7ededfff35ea75fff94123661a768" /><dependencies><group targetFramework="net8.0-windows7.0" /></dependencies><frameworkReferences><group targetFramework="net8.0-windows7.0"><frameworkReference name="Microsoft.WindowsDesktop.App.WindowsForms" /></group></frameworkReferences><contentFiles><files include="any/net8.0-windows7.0/PkgA.pdb" buildAction="Content" copyToOutput="false" /><files include="any/net8.0-windows7.0/PkgA.xml" buildAction="Content" copyToOutput="false" /></contentFiles></metadata></package>