<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <TargetFramework>$(SdkTargetFramework)</TargetFramework>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
    <ServerGarbageCollection>true</ServerGarbageCollection>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.FSharp.Compiler" ExcludeAssets="contentFiles" GeneratePathProperty="true" />
    <PackageReference Include="Microsoft.Build.Framework" />
    <PackageReference Include="Microsoft.Build.Tasks.Core" />
    <PackageReference Include="Microsoft.Build.Utilities.Core" />
  </ItemGroup>

   <Target Name="_ResolvePublishNuGetPackagePdbsAndXml"
        AfterTargets="_ResolveCopyLocalAssetsForPublish">
    <PropertyGroup>
        <FSharpCorePath Condition="'$(DotNetFinalVersionKind)'!='release'">Shipping</FSharpCorePath>
        <FSharpCorePath Condition="'$(DotNetFinalVersionKind)'=='release'">Release</FSharpCorePath>
        <FSharpTfm>net8.0</FSharpTfm>
        <!-- In full product source-only mode, fsharp currently builds net9.0. In repo source-only modes, non VMR builds, or MSFT VMR builds,
             it's net8.0. -->
        <FSharpTfm Condition="'$(DotNetBuildSourceOnly)' == 'true' and '$(DotNetBuildOrchestrator)' == 'true'">net9.0</FSharpTfm>
    </PropertyGroup>
    <ItemGroup>
        <ResolvedFileToPublish
          Include="$(PkgMicrosoft_FSharp_Compiler)/lib/$(FSharpTfm)/FSharp.Core.xml"
          CopyToPublishDirectory="PreserveNewest"
          DestinationSubPath="FSharp.Core.xml"
          RelativePath="FSharp.Core.xml"
          TargetPath="FSharpCore.xml" />
        <FilesToCopyFromFSharpCompilerPackage Include="$(PkgMicrosoft_FSharp_Compiler)/contentFiles/$(FSharpCorePath)/FSharp.Core.*.nupkg" SubDir="library-packs\"/>
        <FilesToCopyFromFSharpCompilerPackage Include="$(PkgMicrosoft_FSharp_Compiler)/contentFiles/$(FSharpCorePath)/Microsoft.FSharp.Core.NetSdk.props" SubDir="" />
        <FilesToCopyFromFSharpCompilerPackage Include="$(PkgMicrosoft_FSharp_Compiler)/contentFiles/any/any/*" Exclude="$(PkgMicrosoft_FSharp_Compiler)/contentFiles/any/any/Microsoft.FSharp.Core.NetSdk.props" SubDir="" />
    </ItemGroup>
    <ItemGroup>
        <ResolvedFileToPublish
          Include="@(FilesToCopyFromFSharpCompilerPackage)"
          CopyToPublishDirectory="PreserveNewest"
          DestinationSubPath="%(FilesToCopyFromFSharpCompilerPackage.SubDir)%(Filename)%(Extension)"
          RelativePath="%(FilesToCopyFromFSharpCompilerPackage.SubDir)%(Filename)%(Extension)"
          TargetPath="%(FilesToCopyFromFSharpCompilerPackage.SubDir)%(Filename)%(Extension)" />
    </ItemGroup>

  </Target>
</Project>
