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

	<PropertyGroup>
		<TargetFrameworks>net10.0-android</TargetFrameworks>
		<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">net10.0-windows10.0.19041.0</TargetFrameworks>
		<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('osx'))">$(TargetFrameworks);net10.0-ios;net10.0-maccatalyst</TargetFrameworks>

		<!-- Note for MacCatalyst:
		The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
		When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
		The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
		either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
		<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->

		<OutputType>Exe</OutputType>
		<RootNamespace>Hua.Todo.Maui</RootNamespace>
		<UseMaui>true</UseMaui>
		<SingleProject>true</SingleProject>
		<ImplicitUsings>enable</ImplicitUsings>
		<Nullable>enable</Nullable>
		<CodePage>65001</CodePage>

		<!-- Android SDK Path - Fallback for local development -->
		<AndroidSdkDirectory Condition="'$(AndroidSdkDirectory)' == '' and Exists('$(USERPROFILE)\AppData\Local\Android\Sdk')">$(USERPROFILE)\AppData\Local\Android\Sdk</AndroidSdkDirectory>

		<!-- Display name -->
		<ApplicationTitle>代办</ApplicationTitle>

		<!-- App Identifier -->
		<ApplicationId>com.companyname.Hua.Todo.maui</ApplicationId>

		<!-- Versions -->
		<Version>1.2.0/Version>
		<ApplicationDisplayVersion>$(Version)</ApplicationDisplayVersion>
		<ApplicationVersion>1</ApplicationVersion>

		<!-- Assembly Info -->
		<AssemblyTitle>待办</AssemblyTitle>
		<AssemblyProduct>待办</AssemblyProduct>
		<AssemblyCompany>Hua.Todo</AssemblyCompany>
		<AssemblyCopyright>Copyright 2024</AssemblyCopyright>

		<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
		<WindowsPackageType>None</WindowsPackageType>

		<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
		<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.0</SupportedOSPlatformVersion>
		<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
		<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
		<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>

		<TodoWebDir>$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)/../Hua.Todo.Web'))</TodoWebDir>
		<TodoWebDistDir>$(TodoWebDir)\dist</TodoWebDistDir>
		<SkipWebBuild>false</SkipWebBuild>
		<ForceWebBuild>false</ForceWebBuild>
	</PropertyGroup>

	<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
		<ApplicationIcon>icon.ico</ApplicationIcon>
	</PropertyGroup>

	<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net10.0-android|AnyCPU'">
	  <AndroidPackageFormat>aab</AndroidPackageFormat>
	  <AndroidUseAapt2>True</AndroidUseAapt2>
	  <AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
	</PropertyGroup>

	<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net10.0-android|AnyCPU'">
	  <Optimize>False</Optimize>
	  <EnableMauiImageProcessing>false</EnableMauiImageProcessing>
	  <DisableResizetizer>true</DisableResizetizer>
	  <AndroidPackageFormat>apk</AndroidPackageFormat>
	  <AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
	  <AndroidUseSharedRuntime>True</AndroidUseSharedRuntime>
	  <AndroidEnableFastDeployment>True</AndroidEnableFastDeployment>
	  <AndroidFastDeploymentType>Assemblies</AndroidFastDeploymentType>
	  <EmbedAssembliesIntoApk>False</EmbedAssembliesIntoApk>
	  <AndroidSupportedAbis>x86_64</AndroidSupportedAbis>
	  <UseAppHost>false</UseAppHost>
	</PropertyGroup>

	<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net10.0-ios|AnyCPU'">
	  <Optimize>False</Optimize>
	</PropertyGroup>

	<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net10.0-maccatalyst|AnyCPU'">
	  <Optimize>False</Optimize>
	</PropertyGroup>

	<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net10.0-windows10.0.19041.0|AnyCPU'">
	  <Optimize>False</Optimize>
	</PropertyGroup>

	<ItemGroup>
		<!-- App Icon -->
		<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

		<!-- Splash Screen -->
		<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />

		<!-- Images -->
		<MauiImage Include="Resources\Images\*" />
		<MauiImage Update="Resources\Images\icon.jpg" Resize="True" BaseSize="256,256" />
		<MauiImage Update="Resources\Images\icon.jpg" Resize="True" BaseSize="300,185" />
		
		<!-- Custom Fonts -->
		<MauiFont Include="Resources\Fonts\*" />

		<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
		<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
		<MauiAsset Include="appsettings.json" LogicalName="appsettings.json" />
	</ItemGroup>

	<ItemGroup>
		<PackageReference Include="Microsoft.Maui.Controls" Version="10.0.51" />
		<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="10.0.5" />
		<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.5" />
		<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.2" />
		<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.5" />
	</ItemGroup>

	<ItemGroup>
		<ProjectReference Include="..\Hua.Todo.Application\Hua.Todo.Application.csproj" />
	</ItemGroup>

	<ItemGroup>
		<EmbeddedResource Include="icon.ico" />
	</ItemGroup>

	<ItemGroup>
		<Content Include="appsettings.json" CopyToOutputDirectory="PreserveNewest" />
	</ItemGroup>

	<ItemGroup Condition="'$(TargetFramework)' == 'net10.0-windows10.0.19041.0'">
		<Content Include="icon.ico" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
	</ItemGroup>

	<ItemGroup Condition="'$(TargetFramework)' == 'net10.0-windows10.0.19041.0'">
		<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.28000.1721" />
		<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.1" />
		<PackageReference Include="System.Drawing.Common" Version="10.0.5" />
		<FrameworkReference Include="Microsoft.AspNetCore.App" />
		<FrameworkReference Include="Microsoft.WindowsDesktop.App" />
	</ItemGroup>

	<ItemGroup Condition="'$(TargetFramework)' == 'net10.0-windows10.0.19041.0' And '$(Configuration)' == 'Debug'">
		<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.7" />
	</ItemGroup>

	<ItemGroup Condition="'$(TargetFramework)' == 'net10.0-maccatalyst'">
		<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
	</ItemGroup>

	<ItemGroup>
	  <Folder Include="wwwroot\" />
	</ItemGroup>

	<ItemGroup Condition="'$(TargetFramework)' == 'net10.0-windows10.0.19041.0'">
		<!-- Windows embedded server serves static files from AppContext.BaseDirectory\wwwroot. -->
		<Content Include="wwwroot\**\*" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
	</ItemGroup>

	<!-- Build web assets into MAUI `wwwroot` so both Windows publish and Android packaging can reuse the same folder. -->
	<Target Name="BuildTodoWeb" BeforeTargets="UpdateAndroidAssets;BeforeBuild" Condition="'$(SkipWebBuild)' != 'true' And Exists('$(TodoWebDir)') And ('$(ForceWebBuild)' == 'true' Or !Exists('$(MSBuildProjectDirectory)\wwwroot\index.html'))">
		<Exec Command="npm ci" WorkingDirectory="$(TodoWebDir)" Condition="Exists('$(TodoWebDir)\package-lock.json') And !Exists('$(TodoWebDir)\node_modules')" />
		<Exec Command="npm install" WorkingDirectory="$(TodoWebDir)" Condition="!Exists('$(TodoWebDir)\package-lock.json') And !Exists('$(TodoWebDir)\node_modules')" />
		<Exec Command="npm run build:maui" WorkingDirectory="$(TodoWebDir)" />
	</Target>

	<Target Name="SyncTodoWebDistToMauiWwwroot" BeforeTargets="ProcessMauiAssets" DependsOnTargets="BuildTodoWeb" Condition="'$(TargetFramework)' == 'net10.0-android' And '$(UseDistSyncToWwwroot)' == 'true' And Exists('$(TodoWebDistDir)\index.html')">
		<ItemGroup>
			<_TodoWebDistFiles Include="$(TodoWebDistDir)\**\*" />
		</ItemGroup>

		<RemoveDir Directories="$(MSBuildProjectDirectory)\wwwroot" Condition="Exists('$(MSBuildProjectDirectory)\wwwroot')" />
		<MakeDir Directories="$(MSBuildProjectDirectory)\wwwroot" />

		<Copy SourceFiles="@(_TodoWebDistFiles)" DestinationFiles="@(_TodoWebDistFiles->'$(MSBuildProjectDirectory)\wwwroot\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />

		<ItemGroup>
			<MauiAsset Include="@(_TodoWebDistFiles)">
				<LogicalName>wwwroot/%(RecursiveDir)%(Filename)%(Extension)</LogicalName>
			</MauiAsset>
		</ItemGroup>
	</Target>

	<Target Name="IncludeMauiWwwrootAsMauiAssets" BeforeTargets="ProcessMauiAssets" DependsOnTargets="BuildTodoWeb" Condition="'$(TargetFramework)' == 'net10.0-android' And Exists('$(MSBuildProjectDirectory)\wwwroot\index.html')">
		<ItemGroup>
			<_MauiWwwrootFiles Include="$(MSBuildProjectDirectory)\wwwroot\**\*" />
		</ItemGroup>

		<ItemGroup>
			<MauiAsset Include="@(_MauiWwwrootFiles)">
				<LogicalName>wwwroot/%(RecursiveDir)%(Filename)%(Extension)</LogicalName>
			</MauiAsset>
		</ItemGroup>
	</Target>
</Project>















