I have some native dll which must be copied in the bin folder with platform conditions. And I want them to be copied to the bin folder of projects referencing this project.
If I set the build action to Content, they will be copied to the bin folder but with the folder structure kept so they will not be in the bin folder but in sub folders. So when running the program, it will not be able to resolve the dll because they are in a subfolder.
For example if I have this code in the project file
<Choose>
<When Condition=" '$(Platform)'=='x86' ">
<ItemGroup>
<Content Include="nativedll\somelib\x86\somelib.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</When>
<When Condition=" '$(Platform)'=='x64' ">
<ItemGroup>
<Content Include="nativedll\somelib\x64\somelib.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</When>
</Choose>
The dll will be in the folder bin\nativedll\somelib\x86\somelib.dll
in the case of x86.
So I tried to use Post build script
<PostBuildEvent>
IF "$(Platform)" == "x86" (
xcopy /s /y "$(ProjectDir)\nativedll\somelib\x86" "$(TargetDir)"
)
IF "$(Platform)" == "x64" (
xcopy /s /y "$(ProjectDir)\nativedll\somelib\x64" "$(TargetDir)"
)
</PostBuildEvent>
But the dll are copied in the bin folder of the project but not in the bin folder of projects referencing it.
So my solution right now is to add a post build script in all projects using this one.
Is there a better way to do this in Visual Studio?