I recently started learning .NET and am currently learning to build applications using .NET MAUI.
At the moment, I am following Build mobile and desktop apps with .NET MAUI
When running the .NET MAUI application that is created when creating a new project in Visual Studio, it is able to run and build fine for the windows machine. But when I try to run the android emulator, "Pixel 5 - API 33 (Android 13.0 - API 33)", it starts the emulator but fails the build for the application.
I tried deleting the emulator and redownloading it again to see if it would work but I got the same problem.
Additionally, these are the logs when I try to build application and the target is the android emulator.
Build started... 1>------ Build started: Project: MauiApp1, Configuration: Debug Any CPU ------ Starting emulator pixel_5_-_api_33 ... 1>C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(376,5): error NETSDK1127: The targeting pack Microsoft.Android is not installed. Please restore and try again. 1>C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(376,5): error NETSDK1127: The targeting pack Microsoft.Maui.Core is not installed. Please restore and try again. 1>C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(376,5): error NETSDK1127: The targeting pack Microsoft.Maui.Controls is not installed. Please restore and try again. 1>C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(376,5): error NETSDK1127: The targeting pack Microsoft.Maui.Essentials is not installed. Please restore and try again. 1>Done building project "MauiApp1.csproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== ========== Elapsed 00:00.468 ========== ========== Deploy: 0 succeeded, 0 failed, 0 skipped ========== ========== Elapsed 00:00.468 ========== C:\Program Files (x86)\Android\android-sdk\emulator\emulator.EXE -netfast -accel on -avd pixel_5_-_api_33 -prop monodroid.avdname=pixel_5_-_api_33 Emulator pixel_5_-_api_33 is running.
Update: I decided to create a new project and it was able to run fine. I'm not sure why it didn't work previously but when I looked at the live visual tree the component of the app wouldn't show up so I think that might have something to do with it.
CodePudding user response:
Per your build log, the four targeting packs below were not being completed downloaded by the Visual Studio previously so that's why the build error occurred in Android Emulator.
- Microsoft.Android
- Microsoft.Maui.Core
- Microsoft.Maui.Controls
- Microsoft.Maui.Essentials
When you created a new project, the packs were ready so it would run successfully.