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

  <PropertyGroup>
    <TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
    <OutputType>Exe</OutputType>
    <IsPackable>false</IsPackable>
    <ImplicitUsings>enable</ImplicitUsings>
    <LangVersion>13.0</LangVersion>
    <StartupObject>Markdig.Tests.Program</StartupObject>
    <SpecExecutable>$(MSBuildProjectDirectory)\..\SpecFileGen\bin\$(Configuration)\$(TargetFramework)\SpecFileGen.dll</SpecExecutable>
    <SpecTimestamp>$(MSBuildProjectDirectory)\..\SpecFileGen\bin\$(Configuration)\$(TargetFramework)\SpecFileGen.timestamp</SpecTimestamp>
    <NoWarn>$(NoWarn);NETSDK1138</NoWarn>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
    <PackageReference Include="NUnit" Version="4.3.2" />
    <PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Markdig\Markdig.csproj" />
    <ProjectReference Include="..\SpecFileGen\SpecFileGen.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Using Include="NUnit.Framework" />
  </ItemGroup>

  <ItemGroup>
    <ItemSpecExecutable Include="$(SpecExecutable)" />
    <InputSpecFiles Include="Specs\*.md" />
    <InputSpecFiles Include="NormalizeSpecs\*.md" />
    <InputSpecFiles Include="PlainTextSpecs\*.md" />
    <InputSpecFiles Include="RoundtripSpecs\*.md" />
    <InputSpecFiles Remove="Specs\readme.md" />
    <!-- Allow Visual Studio up-to-date check to verify that nothing has changed - https://github.com/dotnet/project-system/blob/main/docs/up-to-date-check.md -->
    <UpToDateCheckInput Include="@(InputSpecFiles)" />
    <OutputSpecFiles Include="@(InputSpecFiles->'%(RelativeDir)%(Filename).generated.cs')" />
  </ItemGroup>

  <Target Name="GeneratedSpecsFile" BeforeTargets="BeforeCompile;CoreCompile" Inputs="@(ItemSpecExecutable);@(InputSpecFiles)" Outputs="@(ItemSpecExecutable->'%(RelativeDir)%(Filename).timestamp');@(InputSpecFiles->'%(RelativeDir)%(Filename).generated.cs')">
    <Message Importance="high" Text="Regenerating Specs Files" />
    <Exec Command="dotnet $(SpecExecutable)" />
    <WriteLinesToFile File="$(SpecTimestamp)" Lines="$([System.DateTime]::Now)" />
    <ItemGroup>
      <FileWrites Include="$(SpecTimestamp)" />
      <_GeneratedSpecsFile Include="Specs\*.generated.cs" />
      <_GeneratedSpecsFile Include="NormalizeSpecs\*.generated.cs" />
      <_GeneratedSpecsFile Include="PlainTextSpecs\*.generated.cs" />
      <_GeneratedSpecsFile Include="RoundtripSpecs\*.generated.cs" />
      <_GeneratedSpecsFile Remove="@(Compile)" />
      <Compile Include="@(_GeneratedSpecsFile)" />
    </ItemGroup>
  </Target>
</Project>