Search code examples
debuggingmauireleasevisual-studio-2022

Why MAUI App can Debug but Release failed


I Have built a Maui app. It debug well in Android device, but it slow start so I try Release (optimize to speed up startup,if you have another method for optimize to speed up startup tell me here) instead of Debug, but it failed.

here are logs:

Severity    Code    Description Project File    Line    Suppression State
Error       NETSDK1144: Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false.            0   

Severity    Code    Description Project File    Line    Suppression State
Error       IL1032: Root assembly 'obj\Release\net7.0-android\MerciDistribuzione.dll' could not be found.           0   

Solution

  • From debug to Release build maui app, the startup speed of the app is significantly increased, mine is about 3/4 seconds.

    Step 1: select Release instead of Debug.

    Step 2: select the !configuration manager!! under the 'Build' menu bar, select release, the corresponding Build and Deploy Checked both.

    Step 3: Double-click the project (the main project under the solution) to enter the project configuration file, add

    <PropertyGroup >
       <PublishTrimmed>true </PublishTrimmed>
    </PropertyGroup >
    

    (Remember, this added PropertyGroup is only for Release start run. If you want to Debug start run later, you must delete this PublishTrimmed PropertyGroup in the project configuration file.)

    Step 4: under the tool, in the Nuget package manager, it has been downloaded to the project, and Delete unnecessary packages that are not used (you can open a brand new Muai APP1, which is in the default state of Microsoft, open Nuget, compare which packages are added to your project, and then look at your own code to see which ones are needed. Delete the unused ones), start running (it is recommended to delete bin and obj first, and then run)