<Project Sdk="Microsoft.NET.Sdk">

  <Import Project="..\Common.props" />

  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
    <RootNamespace>IPA.Injector</RootNamespace>

    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <GenerateDocumentationFile>false</GenerateDocumentationFile>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <BuildForBeatSaber Condition=" '$(BuildForBeatSaber)' == '' And '$(TargetFramework)' == 'net472' ">true</BuildForBeatSaber>
  </PropertyGroup>

  <PropertyGroup Condition="'$(TargetFramework)' == 'net472'">
    <DefineConstants>$(DefineConstants);NET4</DefineConstants>
  </PropertyGroup>
  <PropertyGroup Condition="'$(TargetFramework)' == 'net35'">
    <DefineConstants>$(DefineConstants);NET3</DefineConstants>
  </PropertyGroup>
  <PropertyGroup Condition="'$(BuildForBeatSaber)' == 'true'">
    <DefineConstants>$(DefineConstants);BeatSaber</DefineConstants>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\IPA.Loader\IPA.Loader.csproj" />
    <ProjectReference Include="..\Net3-Proxy\Net3-Proxy.csproj" Condition=" '$(TargetFramework)' == 'net35' " />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="UnityEngine.CoreModule" Condition=" '$(TargetFramework)' == 'net472' ">
      <HintPath>..\Refs\UnityEngine.CoreModule.Net4.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="UnityEngine.CoreModule" Condition=" '$(TargetFramework)' == 'net35' ">
      <HintPath>..\Refs\UnityEngine.CoreModule.Net3.dll</HintPath>
      <Private>False</Private>
    </Reference>
  </ItemGroup>

  <ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
    <Content Include="..\Libs\I18N.Net4.dll">
      <Link>Libraries\Mono\I18N.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Include="..\Libs\I18N.West.Net4.dll">
      <Link>Libraries\Mono\I18N.West.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Include="..\Libs\Microsoft.CSharp.dll">
      <Link>Libraries\Mono\Microsoft.CSharp.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Include="..\Libs\System.Runtime.Serialization.Net4.dll">
      <Link>Libraries\Mono\System.Runtime.Serialization.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Include="..\Libs\netstandard.dll">
      <Link>Libraries\Mono\netstandard.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

  <ItemGroup>
    <Content Include="..\Libs\thirdparty\*">
      <Link>Libraries\Thirdparty\%(Filename)%(Extension)</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

  <ItemGroup Condition=" '$(TargetFramework)' == 'net35' ">
    <Content Include="..\Libs\I18N.Net3.dll">
      <Link>Libraries\Mono\I18N.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Include="..\Libs\I18N.West.Net3.dll">
      <Link>Libraries\Mono\I18N.West.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Include="..\Libs\System.Runtime.Serialization.Net3.dll">
      <Link>Libraries\Mono\System.Runtime.Serialization.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Mono.Cecil" Version="0.11.4" />
    <PackageReference Include="AsyncBridge" Version="0.3.1" />

    <ProjectReference Include="..\SemVer\SemVer.csproj" />
  </ItemGroup>

  <Target Name="CopyDocumentation" BeforeTargets="Build">
    <ItemGroup>
      <ReferenceFiles Include="%(Reference.RelativeDir)%(Reference.Filename).xml" />
    </ItemGroup>
    <Message Text="Copying documentation" />
    <Copy SourceFiles="@(ReferenceFiles)" DestinationFolder="$(OutputPath)Libs" Condition="Exists('%(RootDir)%(Directory)%(Filename)%(Extension)')" />
  </Target>

  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Message Text="Relocating" Importance="normal" />
    <ItemGroup>
      <SystemFiles Include="$(OutputPath)IPA.Injector.*" />
      <SystemFiles Include="$(OutputPath)IPA.Loader.*" />
      <SystemFiles Include="$(OutputPath)AsyncBridge.*" />
      <SystemFiles Include="$(OutputPath)System.*" />
      <SystemFiles Include="$(OutputPath)Portable.System.*" />
      <SystemFiles Include="$(OutputPath)Net3-Proxy.*" />
      <SystemFiles Include="$(OutputPath)Libraries\Mono\**\*" />
      <OldLibFiles Include="$(OutputPath)Libs\**\*" />
    </ItemGroup>
    <Move SourceFiles="@(SystemFiles)" DestinationFolder="$(OutputPath)Data\Managed" />
    <RemoveDir Directories="$(OutputPath)Libraries\Mono" />

    <Delete Files="@(OldLibFiles)" />
    <RemoveDir Directories="$(OutputPath)Libs" />
    <ItemGroup>
      <LibFiles Include="$(OutputPath)**\*" Exclude="$(OutputPath)Data\**\*;$(OutputPath)Libs\**\*" />
    </ItemGroup>
    <Move SourceFiles="@(LibFiles)" DestinationFolder="$(OutputPath)Libs\" />
    <RemoveDir Directories="$(OutputPath)Libraries\Included" />
    <RemoveDir Directories="$(OutputPath)Libraries" />
  </Target>

  <Import Project="..\Common.targets" />

</Project>
