简体   繁体   中英

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?

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 Condition s.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM