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

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

  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <Version>$(JiaowuBackendVersion)</Version>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <SpaRoot>$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)/../../web'))</SpaRoot>
    <BuildFrontendOnPublish Condition="'$(BuildFrontendOnPublish)' == ''">true</BuildFrontendOnPublish>
    <NpmCommand Condition="'$(OS)' == 'Windows_NT'">call npm.cmd</NpmCommand>
    <NpmCommand Condition="'$(NpmCommand)' == ''">npm</NpmCommand>
  </PropertyGroup>

  <ItemGroup>
    <Content Remove="wwwroot\**\*" />
    <Content Update="appsettings.Development.json" CopyToPublishDirectory="Never" />
    <Content
      Include="..\..\.env.example"
      Link=".env.example"
      CopyToPublishDirectory="PreserveNewest" />
    <Content
      Include="..\..\versions.props"
      Link="versions.props"
      CopyToOutputDirectory="PreserveNewest"
      CopyToPublishDirectory="PreserveNewest" />
  </ItemGroup>

  <ItemGroup>
    <AssemblyMetadata
      Include="SwaggerDocumentVersion"
      Value="$(JiaowuSwaggerVersion)" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="ClosedXML" Version="0.105.1" />
    <PackageReference Include="DocumentFormat.OpenXml" Version="3.5.1" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.10" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="10.0.10" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="10.0.10" />
    <PackageReference Include="Microsoft.Extensions.Caching.Hybrid" Version="10.8.0" />
    <PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="10.0.10" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.10">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.10" />
    <PackageReference Include="MySql.EntityFrameworkCore" Version="10.0.9" />
    <PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.17.0" />
    <PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.17.0" />
    <PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.17.0" />
    <PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.17.0" />
    <PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.17.0" />
    <PackageReference Include="QRCoder" Version="1.8.0" />
    <PackageReference Include="RabbitMQ.Client" Version="7.2.2" />
    <PackageReference Include="SkiaSharp" Version="4.151.1" />
    <PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="4.151.1" />
    <PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="3.0.5" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="10.2.3" />
  </ItemGroup>

  <Target
    Name="BuildVueFrontendForPublish"
    AfterTargets="ComputeFilesToPublish"
    Condition="Exists('$(SpaRoot)/package.json')">
    <Message
      Condition="'$(BuildFrontendOnPublish)' == 'true'"
      Importance="high"
      Text="Building Vue frontend for ASP.NET Core publish..." />
    <Exec
      Condition="'$(BuildFrontendOnPublish)' == 'true'"
      WorkingDirectory="$(SpaRoot)"
      Command="$(NpmCommand) ci" />
    <Exec
      Condition="'$(BuildFrontendOnPublish)' == 'true'"
      WorkingDirectory="$(SpaRoot)"
      Command="$(NpmCommand) run build" />

    <ItemGroup>
      <FrontendFiles Include="$(MSBuildProjectDirectory)\wwwroot\**\*" />
      <ResolvedFileToPublish Include="@(FrontendFiles->'%(FullPath)')">
        <RelativePath>wwwroot\%(RecursiveDir)%(Filename)%(Extension)</RelativePath>
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
        <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
      </ResolvedFileToPublish>
    </ItemGroup>
  </Target>

</Project>
