Skip to content

[build] fix broken incrementality of Mono.Android.csproj#10578

Merged
grendello merged 1 commit intomainfrom
dev/peppers/incremental-mono.android
Nov 7, 2025
Merged

[build] fix broken incrementality of Mono.Android.csproj#10578
grendello merged 1 commit intomainfrom
dev/peppers/incremental-mono.android

Conversation

@jonathanpeppers
Copy link
Member

I noticed this was happening like for every build...

> .\dotnet-local.cmd build .\src\Mono.Android\Mono.Android.csproj -bl
...
Build succeeded with 78 warning(s) in 125.6s

Even with no changes!

I tracked this down to this chain of events:

Mono.Android.csproj
Target CoreCompile
Building target "CoreCompile" completely.
Input file "Android.Runtime\JNIEnv.g.cs" is newer than output file "obj\Debug\net10.0\android-36\Mono.Android.pdb".
...
Target _BuildJNIEnv
Building target "_BuildJNIEnv" completely.
Input file "..\..\bin\BuildDebug\jnienv-gen.dll" is newer than output file "../../src/Mono.Android/Android.Runtime/JNIEnv.g.cs".
...
Target CoreCompile
Building target "CoreCompile" completely.
Input file "D:\src\xamarin-android\bin\Debug\lib\packs\Microsoft.Android.Sdk.Windows\36.1.99\Sdk\AutoImport.props" is newer than output file "obj\Debug\net9.0\jnienv-gen.pdb".

Reviewing the _GenerateBundledVersions MSBuild target, it just runs every time! No Inputs or Outputs are defined, so it is always considered out-of-date.

I created a new _WriteBundledVersionsCache target that writes a cache file with all important properties, and then made _GenerateBundledVersions depend on that target, and added Inputs and Outputs to it.

This appears to speed up our builds significantly!

> .\dotnet-local.cmd build .\src\Mono.Android\Mono.Android.csproj -bl
...
Build succeeded in 2.1s

I noticed this was happening like for *every* build...

    > .\dotnet-local.cmd build .\src\Mono.Android\Mono.Android.csproj -bl
    ...
    Build succeeded with 78 warning(s) in 125.6s

Even with no changes!

I tracked this down to this chain of events:

    Mono.Android.csproj
    Target CoreCompile
    Building target "CoreCompile" completely.
    Input file "Android.Runtime\JNIEnv.g.cs" is newer than output file "obj\Debug\net10.0\android-36\Mono.Android.pdb".
    ...
    Target _BuildJNIEnv
    Building target "_BuildJNIEnv" completely.
    Input file "..\..\bin\BuildDebug\jnienv-gen.dll" is newer than output file "../../src/Mono.Android/Android.Runtime/JNIEnv.g.cs".
    ...
    Target CoreCompile
    Building target "CoreCompile" completely.
    Input file "D:\src\xamarin-android\bin\Debug\lib\packs\Microsoft.Android.Sdk.Windows\36.1.99\Sdk\AutoImport.props" is newer than output file "obj\Debug\net9.0\jnienv-gen.pdb".

Reviewing the `_GenerateBundledVersions` MSBuild target, it just runs
every time! No `Inputs` or `Outputs` are defined, so it is always
considered out-of-date.

I created a new `_WriteBundledVersionsCache` target that writes a
cache file with all important properties, and then made
`_GenerateBundledVersions` depend on that target, and added `Inputs`
and `Outputs` to it.

This appears to speed up our builds significantly!

    > .\dotnet-local.cmd build .\src\Mono.Android\Mono.Android.csproj -bl
    ...
    Build succeeded in 2.1s
@grendello grendello merged commit 1b0c77f into main Nov 7, 2025
59 checks passed
@grendello grendello deleted the dev/peppers/incremental-mono.android branch November 7, 2025 09:06
@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants