-
Notifications
You must be signed in to change notification settings - Fork 529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Xamarin.Android.Build.Tasks] remove usage of Before/AfterTargets #2795
[Xamarin.Android.Build.Tasks] remove usage of Before/AfterTargets #2795
Conversation
Context: https://github.com/jonathanpeppers/MSBuildIncrementalClean Through research into MSBuild, there are two problem we generally want to fix: * We have targets we want to run *before* `IncrementalClean`. Our current implementation uses a private MSBuild target to achieve this. * We have use of `BeforeTargets` and `AfterTargets`, which causes some problems. One problem we have, is that usage of `AfterTargets` causes C# compiler errors to produce extra (and confusing errors): MainActivity.cs(9,7): error CS0246: The type or namespace name 'ClassLibrary1' could not be found (are you missing a using directive or an assembly reference?) Would also trigger this: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2160,5): error MSB4018: The "LinkAssemblies" task failed unexpectedly. System.IO.FileNotFoundException: Could not load assembly 'App1, Version=0.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile? File name: 'App1.dll' at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters) at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.GetAssembly(String fileName) at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res) at Xamarin.Android.Tasks.LinkAssemblies.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [C:\Users\joaqu\source\repos\ClassLibrary21\App1\App1.csproj] And to make matters worse, the noisy/ignorable error is displayed first in the list in the IDE! Going through our targets here, there was a decent bit of rework needed. I also updated our MSBuild "best practices" docs. ~~ IncrementalClean ~~ Using a new technique I figured out: <PropertyGroup> <!--Add to this property as needed here--> <_BeforeIncrementalClean> _AddFilesToFileWrites; </_BeforeIncrementalClean> <CoreBuildDependsOn> $([MSBuild]::Unescape($(CoreBuildDependsOn.Replace('IncrementalClean;', '$(_BeforeIncrementalClean);IncrementalClean;')))) </CoreBuildDependsOn> </PropertyGroup> We can specify targets that need to run *before* `IncrementalClean` without using `BeforeTargets`. I then went through and fixed the following targets: * `_AddFilesToFileWrites` * `_CompileDex` * `_PrepareAssemblies` ~~ _SetupApplicationJavaClass ~~ This target had: <Target Name="_SetupApplicationJavaClass" AfterTargets="_ResolveMonoAndroidSdks" DependsOnTargets="$(_BeforeSetupApplicationJavaClass)"> I moved the contents of this target to `_ResolveMonoAndroidSdks`. Usage of `$(_BeforeSetupApplicationJavaClass)` will need to change to use `$(_ResolveMonoAndroidSdksDependsOn)` instead. ~~ _ResolveMonoAndroidFramework ~~ This target was empty, and I could not find anything using it. <Target Name="_ResolveMonoAndroidFramework" DependsOnTargets="GetReferenceAssemblyPaths" /> I removed it, and used `GetReferenceAssemblyPaths` where applicable. ~~ _SetLatestTargetFrameworkVersion ~~ `_CreateAapt2VersionCache` was using `AfterTargets="_SetLatestTargetFrameworkVersion"`, so this target needed to be reworked. I renamed `_SetLatestTargetFrameworkVersion` to `_ResolveSdks`. I created a new, empty `_SetLatestTargetFrameworkVersion` target that depends on: * `_ResolveSdks` then * `_CreateAapt2VersionCache` ~~ Changes needed in monodroid ~~ * Usage of `$(_BeforeSetupApplicationJavaClass)` will need to use `$(_ResolveMonoAndroidSdksDependsOn)` * Need to do a general audit for `BeforeTargets` & `AfterTargets`
The macOS PR Release Build failed for two reasons:
(1) can be fixed in the Freestyle build definition. (2) is ignorable. |
This looks ok. One question I still have is how |
@dellis1972 I think I will move onto looking at Theoretically, I'll be able to remove a lot of the |
The Windows failures seem to be parallel related:
Maybe it's time to figure out something to make these tests more reliable? Most of the issues are around downloading files / and NuGet. |
Context: https://github.com/jonathanpeppers/MSBuildIncrementalClean
Through research into MSBuild, there are two problem we generally want
to fix:
IncrementalClean
. Ourcurrent implementation uses a private MSBuild target to achieve
this.
BeforeTargets
andAfterTargets
, which causes someproblems.
One problem we have, is that usage of
AfterTargets
causes C#compiler errors to produce extra (and confusing errors):
Would also trigger this:
And to make matters worse, the noisy/ignorable error is displayed
first in the list in the IDE!
Going through our targets here, there was a decent bit of rework
needed. I also updated our MSBuild "best practices" docs.
IncrementalClean
Using a new technique I figured out:
We can specify targets that need to run before
IncrementalClean
without using
BeforeTargets
.I then went through and fixed the following targets:
_AddFilesToFileWrites
_CompileDex
_PrepareAssemblies
_SetupApplicationJavaClass
This target had:
I moved the contents of this target to
_ResolveMonoAndroidSdks
.Usage of
$(_BeforeSetupApplicationJavaClass)
will need to change touse
$(_ResolveMonoAndroidSdksDependsOn)
instead._ResolveMonoAndroidFramework
This target was empty, and I could not find anything using it.
I removed it, and used
GetReferenceAssemblyPaths
where applicable._SetLatestTargetFrameworkVersion
_CreateAapt2VersionCache
was usingAfterTargets="_SetLatestTargetFrameworkVersion"
, so this targetneeded to be reworked.
I renamed
_SetLatestTargetFrameworkVersion
to_ResolveSdks
.I created a new, empty
_SetLatestTargetFrameworkVersion
target thatdepends on:
_ResolveSdks
then_CreateAapt2VersionCache
Changes needed in monodroid
$(_BeforeSetupApplicationJavaClass)
will need to use$(_ResolveMonoAndroidSdksDependsOn)
BeforeTargets
&AfterTargets