Commit 1dfbf6f
authored
[TrimmableTypeMap] Generate the typemap before the NativeAOT inner build so the IDE Compile→Sign flow works (#11789)
### Summary
The NativeAOT trimmable typemap (the generated Java ↔ .NET type map) is consumed by the **inner per-RID ILC build** — via `_AddTrimmableTypeMapAssembliesToIlc` → `_ReadGeneratedTrimmableTypeMapAssemblies` — which reads the generated assembly list at `obj/.../typemap/typemap-assemblies.txt`. The inner build cannot *generate* that list: `_GenerateTrimmableTypeMap` is gated to the **outer** build (`'$(_OuterIntermediateOutputPath)' == ''`).
`_GenerateTrimmableTypeMap`'s only trigger is `AfterTargets="CoreCompile"`. That hook does not fire when compilation is already up-to-date — which is exactly what happens in the IDE's split build, where Visual Studio (`BuildingInsideVisualStudio=true`) runs **`Compile`** and **`SignAndroidPackage`** as two separate MSBuild invocations. During the `SignAndroidPackage` call the C# is already compiled, so `CoreCompile` is skipped, the typemap is never generated, and the inner ILC build fails with:
```
Trimmable typemap assembly list '.../typemap/typemap-assemblies.txt' was not found
```
A regular command-line `Build` works because all targets run in one continuous invocation; only the IDE Compile→Sign sequence hits this. Reproduced by the `DesignTimeBuildSignAndroidPackage(NativeAOT)` test.
Fixes #11775.
### Fix
Add a target that forces the typemap to be generated in the **outer** build before `_ResolveAssemblies` spawns the inner per-RID ILC build:
```xml
<Target Name="_EnsureTrimmableTypeMapGeneratedForNativeAotInnerBuild"
Condition=" '$(RuntimeIdentifier)' == '' "
BeforeTargets="_ResolveAssemblies"
DependsOnTargets="_GenerateTrimmableTypeMap" />
```
Instead of relying on the fragile `AfterTargets="CoreCompile"` hook, generation is anchored to `_ResolveAssemblies`, which always runs before the inner build and runs *after* compilation (it consumes `@(IntermediateAssembly)`), so the generator still observes the compiled app assembly. This mirrors the CoreCLR `_AddTrimmableTypeMapToLinker` target, which forces generation before the (outer) ILLink.
### Risk
Low and well-scoped: the new target is conditioned to the outer build (`RuntimeIdentifier == ''`) and lives in the NativeAOT trimmable targets file; it only ensures an already-required step has run. No effect on CoreCLR, managed, or MonoVM paths.
### Testing
Verified locally: `DesignTimeBuildSignAndroidPackage(NativeAOT)` now passes (was failing); `DesignTimeBuildSignAndroidPackage(CoreCLR)` continues to pass.
Sliced out of #11617 for focused review.1 parent 10d3a5d commit 1dfbf6f
1 file changed
Lines changed: 25 additions & 0 deletions
File tree
- src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets
Lines changed: 25 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
44 | 69 | | |
45 | 70 | | |
46 | 71 | | |
| |||
0 commit comments