I want to copy an assembly (let's call it Plugin1.dll) into several different applications that can make use of this plugin. Currently I'm doing something like this in the plugins .csproj/.fsproj file:
<ItemGroup>
<Applications Include="..\..\..\Applications\AppA\bin\$(Configuration)" />
<Applications Include="..\..\..\Applications\AppB\bin\$(Configuration)" />
<Applications Include="..\..\..\Applications\AppC\bin\$(Configuration)" />
</ItemGroup>
<Target Name="CopyPlugin" AfterTargets="Build">
<ItemGroup>
<ApplicationOutDirs Include="$([System.IO.Directory]::GetDirectories('%(Applications.Identity)'))" />
</ItemGroup>
<Copy SourceFiles="$(TargetDir)$(TargetFileName)" DestinationFolder="%(ApplicationOutDirs.Identity)\Plugins\" SkipUnchangedFiles="true" />
</Target>
Like this I can copy my Plugin1.dll into AppA, AppB and AppC.
However I would need to copy 11 lines of code into all of my 200+ plugin project files.
Is there any way to create a build task that I could reuse here. I'm thinking of something like this:
<CopyPlugin Application="AppA" Directory="Plugins" />
<CopyPlugin Application="AppB" Directory="Plugins" />
<CopyPlugin Application="AppC" Directory="Plugins" />
I saw there are ways to add tasks with UsingTask and specifying C# code inline to implement it, but I'm looking for an easier way...
FYI: I'm using ApplicationOutDirs (target batching) here because the apps can be built for .NET Framework 4.8 and .NET 6 at the same time. So there are sub-folders like net48 and net6.0 in bin/Debug or bin/Release respectively.