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

  <PropertyGroup>
    <TargetFrameworks>net9.0;net8.0</TargetFrameworks>
  </PropertyGroup>

  <Target Name="CallComposeStore" AfterTargets="Publish">
    <PropertyGroup>
      <AdditionalDepsPath>$(OutputDir)\AdditionalDeps</AdditionalDepsPath>
      <StoreOutputBasePath>$(OutputDir)\store\</StoreOutputBasePath>
      <AdditionalDepsPath Condition="'$(TracerHomePath)' != ''">$(TracerHomePath)\AdditionalDeps</AdditionalDepsPath>
      <StoreOutputBasePath Condition="'$(TracerHomePath)' != ''">$(TracerHomePath)\store</StoreOutputBasePath>
      <NukePlatform Condition="'$(NukePlatform)' == ''">x64</NukePlatform>
    </PropertyGroup>

    <ItemGroup>
      <StoreRuntime Include="x86" Condition="'$(OS)' == 'Windows_NT'">
        <Platform>x86</Platform>
        <StorePath>$(StoreOutputBasePath)</StorePath>
      </StoreRuntime>
      <StoreRuntime Include="x64" Condition="'$(NukePlatform)' == 'x64'">
        <Platform>x64</Platform>
        <StorePath>$(StoreOutputBasePath)</StorePath>
      </StoreRuntime>
      <StoreRuntime Include="arm64" Condition="'$(NukePlatform)' == 'arm64'">
        <Platform>arm64</Platform>
        <StorePath>$(StoreOutputBasePath)</StorePath>
      </StoreRuntime>
    </ItemGroup>
    
    <Message Text="Calling ComposeStore for TargetFramework='$(TargetFramework)' and NukePlatform='$(NukePlatform)'" Importance="high" />
    
    <ItemGroup>
      <ProjectsToBuild Include="Package.xml">
        <Properties>TargetFramework=$(TargetFramework);PlatformTarget=%(StoreRuntime.Platform);RuntimeIdentifier=%(StoreRuntime.Identity);SkipOptimization=true;ComposeDir=%(StoreRuntime.StorePath);CreateProfilingSymbols=false;Version=$(SemanticVersion4parts);NuGetPackageRootOriginal=$(NuGetPackageRoot);Environment=$(Environment)</Properties>
      </ProjectsToBuild>
    </ItemGroup>
    <MSBuild Projects="@(ProjectsToBuild)" Targets="ComposeStore" />
  </Target>

</Project>
