<Project>
  <!-- Implicit SDK props import -->
  <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />

  <!-- Default RuntimeIdentifier to the host architecture if not specified -->
  <PropertyGroup Condition="'$(RuntimeIdentifier)' == ''">
    <RuntimeIdentifier Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X64'">win-x64</RuntimeIdentifier>
    <RuntimeIdentifier Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X86'">win-x86</RuntimeIdentifier>
    <RuntimeIdentifier Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">win-arm64</RuntimeIdentifier>
  </PropertyGroup>

  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <EnableDefaultItems>false</EnableDefaultItems>
    <PayloadPath>$(PlatformOutPath)Installer.Windows\bin\$(Configuration)\net472\$(RuntimeIdentifier)\</PayloadPath>
    <InnoSetupVersion>6.3.1</InnoSetupVersion>
    <!-- We already append the RID to our intermediate PayloadPath and also to the
         final installer filenames so there's no need to append to the output path. -->
    <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="../../shared/Git-Credential-Manager/Git-Credential-Manager.csproj" ReferenceOutputAssembly="false" />
  </ItemGroup>

  <ItemGroup>
    <None Include="Setup.iss" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Tools.InnoSetup" Version="$(InnoSetupVersion)" />
  </ItemGroup>

  <!-- Implicit SDK targets import (so we can override the default targets below) -->
  <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

  <Target Name="CoreCompile" Condition="'$(OSPlatform)'=='windows'">
    <PropertyGroup>
      <InnoSetupCommandSystem>"$(NuGetPackageRoot)Tools.InnoSetup\$(InnoSetupVersion)\tools\ISCC.exe" /DPayloadDir="$(PayloadPath)" /DInstallTarget=system /DGcmRuntimeIdentifier="$(RuntimeIdentifier)" "$(RepoSrcPath)\windows\Installer.Windows\Setup.iss" /O"$(OutputPath)"</InnoSetupCommandSystem>
      <InnoSetupCommandUser>"$(NuGetPackageRoot)Tools.InnoSetup\$(InnoSetupVersion)\tools\ISCC.exe" /DPayloadDir="$(PayloadPath)" /DInstallTarget=user /DGcmRuntimeIdentifier="$(RuntimeIdentifier)" "$(RepoSrcPath)\windows\Installer.Windows\Setup.iss" /O"$(OutputPath)"</InnoSetupCommandUser>
    </PropertyGroup>

    <Message Text="Lay Out" Importance="High" />
    <Exec Condition="'$(NoLayout)'!='true'"
          ConsoleToMSBuild="true"
          Command="powershell.exe –NonInteractive –ExecutionPolicy Unrestricted -Command &quot;&amp; {&amp;'$(MSBuildProjectDirectory)\layout.ps1' -Configuration '$(Configuration)' -Output '$(PayloadPath)' -RuntimeIdentifier '$(RuntimeIdentifier)'; if ($?) { exit 0 } else { exit 1 }}&quot;"
          IgnoreExitCode="true">
      <!-- If we want to display the console output if the exit code is not 0, we need to capture it and then output it using the <Error /> below -->
      <Output TaskParameter="ExitCode" PropertyName="ExitCodeOfExec" />
      <Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
    </Exec>
    <Error Condition="'$(NoLayout)'!='true' AND '$(ExitCodeOfExec)' != '0'" Text="Layout script failed with exit code $(ExitCodeOfExec) and message $(OutputOfExec)" />
    <Message Text="$(InnoSetupCommandSystem)" Importance="High" />
    <Exec Command="$(InnoSetupCommandSystem)" />
    <Message Text="$(InnoSetupCommandUser)" Importance="High" />
    <Exec Command="$(InnoSetupCommandUser)" />
  </Target>

  <!-- We don't produce or copy any dependent files for this project -->
  <Target Name="CopyFilesToOutputDirectory" />
  <Target Name="CoreClean">
    <RemoveDir Directories="$(ProjectOutPath)" />
  </Target>

</Project>
