Skip to content

Instantly share code, notes, and snippets.

@roozbehid
Last active July 15, 2024 21:01
Show Gist options
  • Select an option

  • Save roozbehid/65719edd867690ce5191c244e41e63c5 to your computer and use it in GitHub Desktop.

Select an option

Save roozbehid/65719edd867690ce5191c244e41e63c5 to your computer and use it in GitHub Desktop.
MSBuild hack to copy output of a reference project into output. Reference project can be from other language like c++
<!--
I find myself using this a lot to coordinate incompatible reference types. but still project dependencies.
Example 1. CSProj project referencing a C++ project which also brings some other native dependencies
Example 2. .net core project running another project as .net48 executable, but referencing directly causes so much dll hell due to incompatibility of frameworks.
This way you can put them in correct folder location
-->
<Target Name="CopyPublishedFiles" AfterTargets="BeforeBuild">
<MSBuild Projects="..\..\..\your_non_assembly_dependency.vcxproj" Targets="Publish;PublishItemsOutputGroup" RebaseOutputs="true" Properties="Configuration=$(Configuration)">
<Output TaskParameter="TargetOutputs" ItemName="_PublishOutputs" />
</MSBuild>
<Copy SourceFiles="@(_PublishOutputs)" DestinationFolder="$(OutDir)\Native\MyDLLs\%(RecursiveDir)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" />
</Target>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment