I have a NuGet package in which is an extra file packaged as a Content in contentFiles
folder.
Then I have two C# projects with SDK-style .csproj - A and B where Project B references Project A as a ProjectReference
and there is a classic PackageReference
of a NuGet package in the Project A like this:
NuGet package ← Project A ← Project B
My problem is that the extra file gets correctly copied to the build output of Project A, but it won't get copied to the output of Project B unless I do it manually.
Is there a way how to force copy the extra file from the NuGet dependency transitively to the Project B build output?
The only way I can think of is custom Post-build event with xcopy
command but it's more of a workaround than a real solution.
Thanks for any advice in advance!
You can add additional build targets in which you are able to specify that the content files should be copied.
Add build/MyNuGetPackage.targets
to the NuGet package:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<!-- For all files in /contentFiles -->
<Content Include="$(MSBuildThisFileDirectory)..\contentFiles\**\*.*">
<!-- Copy to output directory on build -->
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
This will copy all content files of this package into the output folder, including cases where this package is transitively referenced.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With