Acrotygma
Acrotygma

Reputation: 2569

MSBuild - copy files based on platform

I have some native dlls that come in 2 flavors - built for x86 and x64. Based on my project platform configuration, I would like to copy the right dlls into the folder.

What I tried

<ItemGroup>
    <_nativex86 Include="native\myNativex86folder\*.*" />
    <_nativex64 Include="native\myNativex64folder\*.*  />
</ItemGroup>

<Target Name="AfterBuild">
    <Copy Condition="$(Platform) == x86"
        SourceFiles = "$(_nativex86)"
        DestinationFolder = "$(OutputPath)native" />
    <Copy Condition="$(Platform) == x64"
        SourceFiles = "$(_nativex64)"
        DestinationFolder = "$(OutputPath)native" />
</Target>

However, nothing gets copied. What could I do?

Upvotes: 1

Views: 1148

Answers (1)

Dmitry
Dmitry

Reputation: 14059

Try the following:

<ItemGroup>
    <_nativex86 Include="native\myNativex86folder\*.*" />
    <_nativex64 Include="native\myNativex64folder\*.*  />
</ItemGroup>

<Target Name="AfterBuild">
    <Copy Condition=" '$(Platform)' == 'x86' "
        SourceFiles = "$(_nativex86)"
        DestinationFolder = "$(TargetDir)native" />
    <Copy Condition=" '$(Platform)' == 'x64' "
        SourceFiles = "$(_nativex64)"
        DestinationFolder = "$(TargetDir)native" />
</Target>

I added quotes for values in the Conditions.

You can try also prepend "native" paths with $(SolutionDir) (or $(ProjectDir), $(OutputPath) etc depending on where the files are located) to make them full paths.

Upvotes: 1

Related Questions