You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NET8 Android binding library generated sources are deleted when app resources are updated #8658
The NET8 Android binding library generates it sources files at obj\$(Configuration)\$(TargetFramework)\generated\src.
When the resources of the corresponding app are updated by MSBuild:UpdateGeneratedFiles the msbuild target PrepareResources is called, which deletes the generated sources.
When debugging this causes problems, because the source has changed.
Building the application fails if resources files are open.
Steps to Reproduce
Create NET8 Android binding library for an .AAR file
Use the binding library in a application as project reference
Build the application
Check the binding library generated source at obj\$(Configuration)\$(TargetFramework)\generated\src
Open the app Android resource and change it
Watch obj\$(Configuration)\$(TargetFramework)\generated\src, the source will be deleted after some delay.
While debugging (hitting a break point) the hot reload window is displayed, because the source files have been deleted.
Did you find any workaround?
Create a file Directory.Build.targets in the Android binding library project directory
Ich have created some log files with Project System Tools 2022 in design mode when opening an Android resource: VSLogFiles.zip
The interesting files are the 3 log files from the NetBinding projects.
The generated sources are deleted in this case.
Cam you share the csproj for one of those files? Usually I'd extract it from the binlog but I cannot open it on the mac as the https://live.msbuildlog.com/ site has not been updated it seems :(.
Looks like the problem is the _ClearGeneratedManagedBindings target. Its currently using the following condition '@(InputJar->Count())' == '0' And '@(EmbeddedJar->Count())' == '0' And '@(LibraryProjectZip->Count())' == '0' And '@(_JavaBindingSource->Count())' == '0'.
All of which are evaluating to 0. Something is missing from the conditon on this target it seems.
Here is one of the binding project files. UsbSerialNetBinding.zip
It also contains a pre build step, that is irrelevant in this case. It only tries to force a regeneration of the source if the source is missing ...
The input file is an .aar that is auto detected by the project.
Cam you share the csproj for one of those files? Usually I'd extract it from the binlog but I cannot open it on the mac as the live.msbuildlog.com site has not been updated it seems :(.
Looks like the problem is the _ClearGeneratedManagedBindings target. Its currently using the following condition '@(InputJar->Count())' == '0' And '@(EmbeddedJar->Count())' == '0' And '@(LibraryProjectZip->Count())' == '0' And '@(_JavaBindingSource->Count())' == '0'.
All of which are evaluating to 0. Something is missing from the conditon on this target it seems.
Shouldn't we check here for @(AndroidLibrary->Count()) == '0' as well?
I mean it's the new way to define a native library dependency for binding projects since net6.0.
I suppose they just forgot to add it to this target.
P.S. As a workaround, try to use old nodes instead of AndroidLibrary in your csproj file (e.g., LibraryProjectZip or EmbeddedJar). At least it fixed an issue in my project
It was done this way for compatibility w/ Xamarin.Android -- and the fact we shared code between .NET 6 and Xamarin.Android.
To be honest it's not quite clear that _CategorizeAndroidLibraries target is called during the same MSBuild process when _ClearGeneratedManagedBindings target is called. I suppose that AndroidLibrary nodes might not be translated into older names due to this reason. I just cannot find the other reason of why changing node to LibraryProjectZip worked out
The new FastUpdate check is what is causing it. It runs some targets which do not play well with the .NET android build system. Working on a fix now. in the mean time adding <DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
to the project will work around the issue.
If you read my first text you see that i have already set <DisableFastUpToDateCheck>true</DisableFastUpToDateCheck> in the project, which was not enough to fix the problem.
I'm not sure if it is the same problem as mentioned in description, but even when "obj\Debug\net8.0-android\generated\src" files are not removed, Intellisense and VS cannot see generated content.
Built binaries contains all the code but when an application project uses dependency on this Android binding project (.NET 8 - ProjectReference or DLL) - it cannot see anything but Android resources.
Shouldn't we check here for @(AndroidLibrary->Count()) == '0' as well?
It was done this way for compatibility w/ Xamarin.Android -- and the fact we shared code between .NET 6 and Xamarin.Android.
To be honest it's not quite clear that _CategorizeAndroidLibraries target is called during the same MSBuild process when _ClearGeneratedManagedBindings target is called. I suppose that AndroidLibrary nodes might not be translated into older names due to this reason. I just cannot find the other reason of why changing node to LibraryProjectZip worked out
@Saratsin 's idea of using EmbeddedJar Include=".." fixes this. Thanks.
Activity
dellis1972 commentedon Jan 22, 2024
@uholeschak
Are you able to provide binlogs which demonstrates the issue?
You can follow the instrucitons at https://github.com/dotnet/msbuild/blob/main/documentation/wiki/Providing-Binary-Logs.md#capturing-binary-logs-through-visual-studio. This will capture ALL data including the design time builds, it will allow us to see what is happening. Note it is important that we do get the design time build logs, as from what you describe the problem is with one of those.
uholeschak commentedon Jan 22, 2024
Ich have created some log files with Project System Tools 2022 in design mode when opening an Android resource:
VSLogFiles.zip
The interesting files are the 3 log files from the NetBinding projects.
The generated sources are deleted in this case.
dellis1972 commentedon Jan 22, 2024
@uholeschak
Cam you share the csproj for one of those files? Usually I'd extract it from the binlog but I cannot open it on the mac as the https://live.msbuildlog.com/ site has not been updated it seems :(.
Looks like the problem is the
_ClearGeneratedManagedBindingstarget. Its currently using the following condition'@(InputJar->Count())' == '0' And '@(EmbeddedJar->Count())' == '0' And '@(LibraryProjectZip->Count())' == '0' And '@(_JavaBindingSource->Count())' == '0'.All of which are evaluating to
0. Something is missing from the conditon on this target it seems.uholeschak commentedon Jan 22, 2024
Here is one of the binding project files.
UsbSerialNetBinding.zip
It also contains a pre build step, that is irrelevant in this case. It only tries to force a regeneration of the source if the source is missing ...
The input file is an .aar that is auto detected by the project.
2 remaining items
Saratsin commentedon Feb 5, 2024
Shouldn't we check here for
@(AndroidLibrary->Count()) == '0'as well?I mean it's the new way to define a native library dependency for binding projects since net6.0.
I suppose they just forgot to add it to this target.
P.S. As a workaround, try to use old nodes instead of
AndroidLibraryin yourcsprojfile (e.g.,LibraryProjectZiporEmbeddedJar). At least it fixed an issue in my projectjonathanpeppers commentedon Feb 5, 2024
No, the new item group is simply translated into the "old" names:
https://github.com/xamarin/xamarin-android/blob/06b1d7f82143fb32b1397b3657de5b22fdcfdf7c/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.AvailableItems.targets#L65-L87
It was done this way for compatibility w/ Xamarin.Android -- and the fact we shared code between .NET 6 and Xamarin.Android.
Saratsin commentedon Feb 5, 2024
To be honest it's not quite clear that
_CategorizeAndroidLibrariestarget is called during the same MSBuild process when_ClearGeneratedManagedBindingstarget is called. I suppose thatAndroidLibrarynodes might not be translated into older names due to this reason. I just cannot find the other reason of why changing node toLibraryProjectZipworked outdellis1972 commentedon Feb 6, 2024
@Saratsin
do you have a diagnostic build log which shows the issue? (via aka.ms/binlog).
It would help to see which ItemGroups your project is picking up.
dellis1972 commentedon Feb 7, 2024
ok good news is I think I repo'd the issue.
The new FastUpdate check is what is causing it. It runs some targets which do not play well with the .NET android build system. Working on a fix now. in the mean time adding
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>to the project will work around the issue.
uholeschak commentedon Feb 7, 2024
If you read my first text you see that i have already set
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>in the project, which was not enough to fix the problem.Domik234 commentedon Mar 25, 2024
I'm not sure if it is the same problem as mentioned in description, but even when "obj\Debug\net8.0-android\generated\src" files are not removed, Intellisense and VS cannot see generated content.
Built binaries contains all the code but when an application project uses dependency on this Android binding project (.NET 8 - ProjectReference or DLL) - it cannot see anything but Android resources.
@Saratsin 's idea of using
EmbeddedJar Include=".."fixes this. Thanks.Add test for Binding Projects
uholeschak commentedon Mar 25, 2024
Thanks, I have now also added to fix the problem:
<LibraryProjectZip Include="..." />[Xamarin.Android.Build.Tasks] DTBs should not rm generator output (#8706
[Xamarin.Android.Build.Tasks] DTBs should not rm generator output
[Xamarin.Android.Build.Tasks] DTBs should not rm generator output (#8835