dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.05k stars 1.73k forks source link

[MacCatallyst-arm64] app file size is extremely large for custom configuration #21332

Closed tounaobun closed 6 months ago

tounaobun commented 6 months ago

Description

The built-in Debug and Release configuration do not meet our project requirement, so I added another one called FRelease( Short for Final Release). To do that, I updated the sln file and csproj file as follows.

sln file

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 25.0.1706.7
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestSign", "TestSign\TestSign.csproj", "{E05F54E7-AB00-4E55-BDAB-E1E8A495737F}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Release|Any CPU = Release|Any CPU
                FRelease|Any CPU = FRelease|Any CPU
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {E05F54E7-AB00-4E55-BDAB-E1E8A495737F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {E05F54E7-AB00-4E55-BDAB-E1E8A495737F}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {E05F54E7-AB00-4E55-BDAB-E1E8A495737F}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {E05F54E7-AB00-4E55-BDAB-E1E8A495737F}.Release|Any CPU.Build.0 = Release|Any CPU
                {E05F54E7-AB00-4E55-BDAB-E1E8A495737F}.FRelease|Any CPU.ActiveCfg = FRelease|Any CPU
        {E05F54E7-AB00-4E55-BDAB-E1E8A495737F}.FRelease|Any CPU.Build.0 = FRelease|Any CPU
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
    GlobalSection(ExtensibilityGlobals) = postSolution
        SolutionGuid = {D2498E04-9AFE-4802-A6D2-069D7BA67899}
    EndGlobalSection
EndGlobal

csproj file

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

    <PropertyGroup>
        <TargetFrameworks>net8.0-maccatalyst</TargetFrameworks>
        <!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
        <!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</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. -->
        <RuntimeIdentifier>maccatalyst-arm64</RuntimeIdentifier>

        <OutputType>Exe</OutputType>
        <RootNamespace>TestSign</RootNamespace>
        <UseMaui>true</UseMaui>
        <SingleProject>true</SingleProject>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>

        <!-- Display name -->
        <ApplicationTitle>TestSign</ApplicationTitle>

        <!-- App Identifier -->
        <ApplicationId>com.companyname.testsign</ApplicationId>

        <!-- Versions -->
        <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
        <ApplicationVersion>1</ApplicationVersion>

        <Configurations>Debug;Release;FRelease</Configurations>

        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-ios|AnyCPU'">
      <CreatePackage>false</CreatePackage>
    </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\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)" />
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
        <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
        <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
    </ItemGroup>

</Project>

Notice that I added this property in csproj file. <Configurations>Debug;Release;FRelease</Configurations>

When I build it using Debug configuration, the app file size is around 70MB, the file size is around 70MB for release configuration. However, as for the custom FRelease configuration, the file size is about 336MB.

Is it a bug or is there something missing for the csproj file? B

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

8.0.3 GA

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

macOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

asi-evin commented 6 months ago

Just a theory, but it's probably compiling as stand-alone in release, so it needs to include the .NET runtime, other DLL's, etc. that don't normally get compiled in for debug.

tounaobun commented 6 months ago

Add SdkOnly resolves this issue.