Hi @Omar , Welcome to Microsoft Q&A,
Add a .targets file, such as MyPackage.targets, to the build or buildTransitive folder of your NuGet package with the following content:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<!-- Set CopyToOutputDirectory for a specific DLL in the package -->
<Content Include="$(MSBuildThisFileDirectory)..\runtimes\win\lib\netstandard2.0\YourDependency.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
$(MSBuildThisFileDirectory) refers to the directory where the current .targets file is located and is used to resolve the path dynamically.
If the DLL exists in a specific package path, such as runtimes/win/lib/netstandard2.0/YourDependency.dll, adjust the path to match the actual location. Make sure the .targets file is correctly embedded in the NuGet package
The directory structure of the NuGet package is as follows:
/build/
MyPackage.targets
/lib/
netstandard2.0/
YourDependency.dll
Rebuild the NuGet package and reinstall it in your project.
A reference solution:MSBuild doesn't copy references (DLL files) if using project dependencies in solution
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.