[Xamarin.Android.Build.Tasks] skip MSBuild targets when project file changes #7673
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context: dotnet/maui#7808
There is currently a bug in VS where adding new MAUI pages edits the
.csproj
file:Unfortunately, this triggers many of the Android MSBuild targets to run again -- when they really don't need to.
Various targets have different forms of:
Understandably, this reduces the chance of bin/obj bugs such as:
I build my project.
I change some setting my my project file.
I expect the MSBuild targets interested in this setting to rebuild.
So I don't think we can blindly delete all instances of
@(_AndroidMSBuildAllProjects)
, but try a few at a time. We can replace this value with$(_AndroidBuildPropertiesCache)
(which isbuild.props
) making sure important properties are stored in this file.Interestingly, even
CoreCompile
reruns if the project file changes:Meaning that any of our targets that depend on the current project's build output is going to run anyway. But we can focus on slow parts of the build like
javac
andd8
/r8
.So far, I updated the following targets:
_ConvertResourcesCases
_CompileBindingJava
and_CompileJava
.java
source file change, adjusted someInputs
_GenerateAndroidAssetsDir
and_GenerateAndroidResourceDir
_BeforeManagedUpdateAndroidResgen
@(AndroidResource)
files change_GenerateJavaStubs
_ManifestMerger
$(AndroidManifestMerger)
added tobuild.props
_GeneratePackageManagerJava
$(AndroidEnableMarshalMethods)
,$(AndroidUseAssemblyStore)
, and$(AndroidEnableAssemblyCompression)
added tobuild.props
._CompileToDalvik
.jar
files change_BuildApkEmbed
_PrepareForSign
.apk
/.aab
files changeThere are still more MSBuild targets that use
@(_AndroidMSBuildAllProjects)
, but this is a start.I added a new test for this scenario.