From 3859395c7b129948bc00dfa5d960b0e0222cbe21 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Thu, 24 Jul 2025 15:15:36 -0500 Subject: [PATCH] Restore "[One .NET] fix GetAndroidDependencies target with --no-restore" Context: https://github.com/dotnet/android/commit/a21d1a7d54e811c89e36969d1214f5e31fc4b63a This reverts commit a84eccb8. I've noticed the following sometimes happens when a new .NET MAUI project is created in VS 2022 on Windows: dotnet\sdk\6.0.200-preview.22055.18\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(267,5): error NETSDK1004: Assets file 'obj\project.assets.json' not found. Run a NuGet package restore to generate this file. I seem to only get this for MAUI projects and only *sometimes*. `dotnet new android` projects seem to always work fine. When this error occurs, I think the dropdown fails to load the device list. What you end up with is the play button that just says `> Android Emulator`. After some amount of "fiddling", you can get the IDE to load the device list. What I think is happening is: 1. NuGet restore takes longer in MAUI projects than `dotnet new android` 2. Sometimes `GetAndroidDependencies` runs *before* NuGet restore, and that triggers the above error. I could validate this hypothesis with: > dotnet new android > dotnet build -t:GetAndroidDependencies --no-restore And I get the above error! I could also reproduce in a test. --- .../Xamarin.Android.Build.Tests/XASdkTests.cs | 13 ++++++++++ .../Xamarin.ProjectTools/Common/DotNetCLI.cs | 4 +++- .../Xamarin.Android.Tooling.targets | 24 ++++++++++++------- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs index 4d6d2d29743..328bc9b3c32 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs @@ -333,5 +333,18 @@ public abstract class Foo : ViewHandler - <_ResolveSdksDependsOnTargets>ResolveTargetingPackAssets + <_ResolveSdksDependsOnTargets>ProcessFrameworkReferences - <_AndroidApiInfo Include="$(MSBuildThisFileDirectory)..\data\*\AndroidApiInfo.xml" /> <_AndroidApiInfoDirectories Include="@(_AndroidApiInfo->'%(RootDir)%(Directory)')" /> - <_ResolveSdksFrameworkRefAssemblyPaths Include="@(Reference->'$([System.String]::Copy('%(RootDir)%(Directory)').TrimEnd('\'))')" Condition=" '%(Reference.FrameworkReferenceName)' != '' " /> + + <_AndroidTargetingPackAssemblyPath + Condition=" '%(TargetingPack.Identity)' == 'Microsoft.NETCore.App' " + Include="$([MSBuild]::ValueOrDefault('%(TargetingPack.Path)', '%(TargetingPack.PackageDirectory)'))\ref\*\System.dll" + /> + <_AndroidTargetingPackAssemblyPath + Condition=" '%(TargetingPack.Identity)' == 'Microsoft.Android' " + Include="$([MSBuild]::ValueOrDefault('%(TargetingPack.Path)', '%(TargetingPack.PackageDirectory)'))\ref\*\Mono.Android.dll" + /> + <_AndroidTargetingPackDirectories Include="@(_AndroidTargetingPackAssemblyPath->'$([System.String]::Copy('%(RootDir)%(Directory)').TrimEnd('\'))')" Condition=" '%(_AndroidTargetingPackAssemblyPath.RootDir)%(_AndroidTargetingPackAssemblyPath.Directory)' != '' " /> <_AndroidAllowMissingSdkTooling Condition=" '$(_AndroidAllowMissingSdkTooling)' == '' ">False - <_XATargetFrameworkDirectories>@(_ResolveSdksFrameworkRefAssemblyPaths->Distinct()) + <_XATargetFrameworkDirectories>@(_AndroidTargetingPackDirectories->Distinct())