<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="PlatformCheck" BeforeTargets="ResolveAssemblyReferences" Condition="(('$(Platform)' != 'x86') AND ('$(Platform)' != 'x64') AND ('$(Platform)' != 'Win32') AND '$(CefSharpAnyCpuSupport)' != 'true')">
    <Error Text="$(MSBuildThisFileName) will work out of the box if you specify platform (x86 / x64). For AnyCPU Support see https://github.com/cefsharp/CefSharp/issues/1714" />
  </Target>
  
  <Target Name="FrameworkVersionCheck" BeforeTargets="ResolveAssemblyReferences" Condition="(('$(TargetFrameworkVersion)' == 'v4.5.1') OR ('$(TargetFrameworkVersion)' == 'v4.5') OR ('$(TargetFrameworkVersion)' == 'v4.0'))">
    <Error Text="CefSharp requires .Net 4.5.2 or higher" />
  </Target>

  <PropertyGroup>
    <CefSharpTargetDir Condition=" '$(CefSharpTargetDir)' == '' ">$(TargetDir)</CefSharpTargetDir>
  </PropertyGroup>

  <Target Name="CefSharpCopyLibs86" BeforeTargets="AfterBuild" Condition="'$(Platform)' == 'x86'">
    <ItemGroup>
      <CefSharpBinaries Include="$(MSBuildThisFileDirectory)..\CefSharp\x86\*.*" />
    </ItemGroup>

    <Message Importance="high" Text="Copying cef.redist x86 binaries" />
    <Copy SourceFiles="@(CefBinaries32)" DestinationFolder="$(CefSharpTargetDir)" SkipUnchangedFiles="true" />
    <Message Importance="high" Text="Copying cef.redist x86 pak files" />
    <Copy SourceFiles="@(CefPakFiles32)" DestinationFolder="$(CefSharpTargetDir)" SkipUnchangedFiles="true" />
    <Message Importance="high" Text="Copying cef.redist x86 locales " />
    <Copy SourceFiles="@(CefLocales32)" DestinationFolder="$(CefSharpTargetDir)\locales" SkipUnchangedFiles="true" />

    <Message Importance="high" Text="-- CefSharp.Common.targets: Copying files from $(MSBuildThisFileDirectory)..\CefSharp\x86 to $(CefSharpTargetDir)" />
    <Copy SourceFiles="@(CefSharpBinaries)" DestinationFolder="$(CefSharpTargetDir)" SkipUnchangedFiles="true" />
  </Target>

  <Target Name="CefSharpCopyLibsWin32" BeforeTargets="AfterBuild" Condition="'$(Platform)' == 'Win32'">
    <ItemGroup>
      <CefSharpBinaries Include="$(MSBuildThisFileDirectory)..\CefSharp\x86\*.*" />
    </ItemGroup>
    <Message Importance="high" Text="Copying cef.redist x86 binaries" />
    <Copy SourceFiles="@(CefBinaries32)" DestinationFolder="$(CefSharpTargetDir)" SkipUnchangedFiles="true" />
    <Message Importance="high" Text="Copying cef.redist x86 pak files" />
    <Copy SourceFiles="@(CefPakFiles32)" DestinationFolder="$(CefSharpTargetDir)" SkipUnchangedFiles="true" />
    <Message Importance="high" Text="Copying cef.redist x86 locales " />
    <Copy SourceFiles="@(CefLocales32)" DestinationFolder="$(CefSharpTargetDir)\locales" SkipUnchangedFiles="true" />

    <Message Importance="high" Text="-- CefSharp.Common.targets: Copying files from $(MSBuildThisFileDirectory)..\CefSharp\x86 to $(CefSharpTargetDir)" />
    <Copy SourceFiles="@(CefSharpBinaries)" DestinationFolder="$(CefSharpTargetDir)" SkipUnchangedFiles="true" />
  </Target>

  <Target Name="CefSharpCopyLibs64" BeforeTargets="AfterBuild" Condition="'$(Platform)' == 'x64'">
    <ItemGroup>
      <CefSharpBinaries Include="$(MSBuildThisFileDirectory)..\CefSharp\x64\*.*" />
    </ItemGroup>
    <Message Importance="high" Text="Copying cef.redist x64 binaries" />
    <Copy SourceFiles="@(CefBinaries64)" DestinationFolder="$(CefSharpTargetDir)" SkipUnchangedFiles="true" />
    <Message Importance="high" Text="Copying cef.redist x64 pak files" />
    <Copy SourceFiles="@(CefPakFiles64)" DestinationFolder="$(CefSharpTargetDir)" SkipUnchangedFiles="true" />
    <Message Importance="high" Text="Copying cef.redist x64 locales " />
    <Copy SourceFiles="@(CefLocales64)" DestinationFolder="$(CefSharpTargetDir)\locales" SkipUnchangedFiles="true" />

    <Message Importance="high" Text="-- CefSharp.Common.targets: Copying files from $(MSBuildThisFileDirectory)..\CefSharp\x64 to $(CefSharpTargetDir)" />
    <Copy SourceFiles="@(CefSharpBinaries)" DestinationFolder="$(CefSharpTargetDir)" SkipUnchangedFiles="true" />
  </Target>

  <Target Name="CefSharpCopyLibsAnyCPU" BeforeTargets="AfterBuild" Condition="'$(Platform)' == 'AnyCPU'">
    <ItemGroup>
      <CefSharpBinaries32 Include="$(MSBuildThisFileDirectory)..\CefSharp\x86\*.*" />
      <CefSharpBinaries64 Include="$(MSBuildThisFileDirectory)..\CefSharp\x64\*.*" />
    </ItemGroup>

    <Copy SourceFiles="@(CefBinaries32)" DestinationFolder="$(CefSharpTargetDir)\x86" SkipUnchangedFiles="true" />
    <Message Importance="high" Text="Copying cef.redist x86 pak files" />
    <Copy SourceFiles="@(CefPakFiles32)" DestinationFolder="$(CefSharpTargetDir)\x86" SkipUnchangedFiles="true" />
    <Message Importance="high" Text="Copying cef.redist x86 locales " />
    <Copy SourceFiles="@(CefLocales32)" DestinationFolder="$(CefSharpTargetDir)\x86\locales" SkipUnchangedFiles="true" />

    <Message Importance="high" Text="Copying cef.redist x64 binaries" />
    <Copy SourceFiles="@(CefBinaries64)" DestinationFolder="$(CefSharpTargetDir)\x64" SkipUnchangedFiles="true" />
    <Message Importance="high" Text="Copying cef.redist x64 pak files" />
    <Copy SourceFiles="@(CefPakFiles64)" DestinationFolder="$(CefSharpTargetDir)\x64" SkipUnchangedFiles="true" />
    <Message Importance="high" Text="Copying cef.redist x64 locales " />
    <Copy SourceFiles="@(CefLocales64)" DestinationFolder="$(CefSharpTargetDir)\x64\locales" SkipUnchangedFiles="true" />

    <Message Importance="high" Text="-- CefSharp.Common.targets: Copying files from $(MSBuildThisFileDirectory)..\CefSharp\x86 to $(CefSharpTargetDir)\x86" />
    <Copy SourceFiles="@(CefSharpBinaries32)" DestinationFolder="$(CefSharpTargetDir)\x86" SkipUnchangedFiles="true" />
    <Message Importance="high" Text="-- CefSharp.Common.targets: Copying files from $(MSBuildThisFileDirectory)..\CefSharp\x64 to $(CefSharpTargetDir)\x64" />
    <Copy SourceFiles="@(CefSharpBinaries64)" DestinationFolder="$(CefSharpTargetDir)\x64" SkipUnchangedFiles="true" />
  </Target>
</Project>
