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

	<PropertyGroup>
		<TargetFrameworks>net10.0-android;net10.0-ios;net10.0-maccatalyst</TargetFrameworks>
		<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net10.0-windows10.0.19041.0</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>TodoList.Maui</RootNamespace>
		<UseMaui>true</UseMaui>
		<SingleProject>true</SingleProject>
		<ImplicitUsings>enable</ImplicitUsings>
		<Nullable>enable</Nullable>
		<CodePage>65001</CodePage>

		<!-- Android SDK Path -->
		<AndroidSdkDirectory>C:\Users\ShaoHua\AppData\Local\Android\Sdk</AndroidSdkDirectory>

		<!-- Display name -->
		<ApplicationTitle>待办事项</ApplicationTitle>

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

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

		<!-- Assembly Info -->
		<AssemblyTitle>待办事项</AssemblyTitle>
		<AssemblyProduct>待办事项</AssemblyProduct>
		<AssemblyCompany>TodoList</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>

		<TodoListWebDir>$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)/../TodoList.Web'))</TodoListWebDir>
		<TodoListWebDistDir>$(TodoListWebDir)\dist</TodoListWebDistDir>
		<SkipWebBuild>false</SkipWebBuild>
		<ForceWebBuild>false</ForceWebBuild>
	</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 Include="icon.jpg" Resize="True" BaseSize="256,256" />
		<MauiImage Update="Resources\Images\dotnet_bot.png" 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="..\TodoList.Application\TodoList.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" />
	</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-maccatalyst'">
		<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
	</ItemGroup>

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

	<Target Name="BuildTodoListWeb"
			BeforeTargets="UpdateAndroidAssets;BeforeBuild"
			Condition="'$(SkipWebBuild)' != 'true' And Exists('$(TodoListWebDir)') And ('$(ForceWebBuild)' == 'true' Or !Exists('$(TodoListWebDistDir)\index.html'))">
		<Exec Command="npm ci" WorkingDirectory="$(TodoListWebDir)"
			  Condition="Exists('$(TodoListWebDir)\package-lock.json') And !Exists('$(TodoListWebDir)\node_modules')" />
		<Exec Command="npm install" WorkingDirectory="$(TodoListWebDir)"
			  Condition="!Exists('$(TodoListWebDir)\package-lock.json') And !Exists('$(TodoListWebDir)\node_modules')" />
		<Exec Command="npm run build" WorkingDirectory="$(TodoListWebDir)" />
	</Target>

	<Target Name="SyncTodoListWebDistToMauiWwwroot"
			BeforeTargets="ProcessMauiAssets"
			DependsOnTargets="BuildTodoListWeb"
			Condition="'$(TargetFramework)' == 'net10.0-android' And Exists('$(TodoListWebDistDir)\index.html')">
		<ItemGroup>
			<_TodoListWebDistFiles Include="$(TodoListWebDistDir)\**\*" />
		</ItemGroup>

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

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

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

	<Target Name="CopyTodoListWebDistToWindowsWwwroot"
			BeforeTargets="Build"
			DependsOnTargets="BuildTodoListWeb"
			Condition="'$(TargetFramework)' == 'net10.0-windows10.0.19041.0' And Exists('$(TodoListWebDistDir)')">
		<ItemGroup>
			<_TodoListWebDistFiles Include="$(TodoListWebDistDir)\**\*" />
		</ItemGroup>

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

		<Copy SourceFiles="@(_TodoListWebDistFiles)"
			  DestinationFiles="@(_TodoListWebDistFiles->'$(TargetDir)wwwroot\%(RecursiveDir)%(Filename)%(Extension)')"
			  SkipUnchangedFiles="true" />
	</Target>
</Project>









