i have a multi-targeting project (net48;net6.0) which depends on a Nuget Package containing framework dependent files (lib/net6.0/Assembly.exe). I want to copy these files from the nuget package to the TargetFramework output directory (net6.0).
I tried to add targets to the nuget package, but the target is only executed for the net48 build, not for the net6.0, because targets are only executed once overall (?).
nuget package csproj contains:
<ItemGroup>
<None Include="$(AssemblyName).targets" Pack="true" PackagePath="build" />
<None Include="$(OutputPath)net6.0\$(AssemblyName).exe" Pack="true" PackagePath="lib\net6.0" Visible="false" />
<None Include="$(OutputPath)net6.0\$(AssemblyName).runtimeconfig.json" Pack="true" PackagePath="lib\net6.0" Visible="false" />
</ItemGroup>
target project contains:
<PackageReference Include="MyNugetpackage" Version="1.0.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
I tried to add a .targets to the nuget package which currently contains:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Condition="'$(TargetFramework)'=='net6.0'">
<None Include="$(MSBuildThisFileDirectory)..\lib\$(TargetFramework)\*.exe" Visible="false">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)..\lib\$(TargetFramework)\*.runtimeconfig.json" Visible="false">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="CopyNet6File"
Condition="'$(TargetFramework)'=='net6.0'"
BeforeTargets="CopyAdditionalFiles">
<Copy SourceFiles="$(MSBuildThisFileDirectory)..\lib\$(TargetFramework)\*.exe"
DestinationFolder="$(TargetDir)"
Retries="10"
SkipUnchangedFiles="true"
OverwriteReadOnlyFiles="true" />
<Copy SourceFiles="$(MSBuildThisFileDirectory)..\lib\$(TargetFramework)\*.runtimeconfig.json"
DestinationFolder="$(TargetDir)"
Retries="10"
SkipUnchangedFiles="true"
OverwriteReadOnlyFiles="true" />
</Target>
</Project>
it doesn't work neither, nothing is copied. Hwo to execute targets for all TargetFrameworks - or - how to copy files for every TargetFrameworks from nuget package ?
Any help really appreciated. Thank you very much.