-
Notifications
You must be signed in to change notification settings - Fork 538
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
NET8 Android binding library generated sources are deleted when app resources are updated #8658
Comments
Are you able to provide binlogs which demonstrates the issue? |
Ich have created some log files with Project System Tools 2022 in design mode when opening an Android resource: |
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 All of which are evaluating to |
Here is one of the binding project files. |
Shouldn't we check here for P.S. As a workaround, try to use old nodes instead of |
No, the new item group is simply translated into the "old" names: 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 |
do you have a diagnostic build log which shows the issue? (via aka.ms/binlog). |
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 |
If you read my first text you see that i have already set |
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 |
Fixes dotnet#8658 Fixes dotnet#8698 The PR fixes an issue where the bindings files in intermediate `generated` folder get deleted on subsequent builds. This causes the entire binding process to run again, slowing down builds. The root fo the problem is the `_ClearGeneratedManagedBindings` target. It was designed to clean out the `generated` folder in the case where no binding libraries were present. However it turns out if was running during a design time build! During design time builds the binding library item groups are not evaluated, so the `_ClearGeneratedManagedBindings` would run.. deleting everything. To fix this issue we only run the `_ClearGeneratedManagedBindings` in a standard build. The good thing is this allowed us time to take a look at our incremental build process for bindings. The binding generator does produce a `.projitems` file which lists all the files it generated. We can use that data to incrementally clean up the `generated` folder of old files. This way code that is no longer needed can be removed. While we know the linker will eventually remove unused classes and types, it is better to not have to compile this stuff in the first place.
Thanks, I have now also added to fix the problem: |
) Fixes: #8658 Fixes: #8698 Design-time builds don't play nicely with binding project builds: % dotnet new androidlib % cat > Example.java <<EOF package e; public class Example { public static void e() { } } EOF % dotnet build -p:DesignTimeBuild=true -v:diag After this initial Design-Time build, we have the following generated source code for the binding: % find obj -iname \*.cs | xargs ls -l -rw-r--r-- 1 user staff 197 Mar 25 19:22 obj/Debug/net8.0-android/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs -rw-r--r-- 1 user staff 441 Mar 25 19:22 obj/Debug/net8.0-android/__Microsoft.Android.Resource.Designer.cs -rw-r--r-- 1 user staff 2975 Mar 25 19:22 obj/Debug/net8.0-android/generated/src/E.Example.cs -rw-r--r-- 1 user staff 1518 Mar 25 19:22 obj/Debug/net8.0-android/generated/src/Java.Interop.__TypeRegistrations.cs -rw-r--r-- 1 user staff 696 Mar 25 19:22 obj/Debug/net8.0-android/generated/src/__NamespaceMapping__.cs -rw-r--r-- 1 user staff 1094 Mar 25 19:22 obj/Debug/net8.0-android/gxa-8706.AssemblyInfo.cs -rw-r--r-- 1 user staff 407 Mar 25 19:22 obj/Debug/net8.0-android/gxa-8706.GlobalUsings.g.cs Run a Design-Time build *again*: % dotnet build -p:DesignTimeBuild=true -v:diag …and we're now missing files (?!): % find obj -iname \*.cs | xargs ls -l -rw-r--r-- 1 user staff 197 Mar 25 19:22 obj/Debug/net8.0-android/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs -rw-r--r-- 1 user staff 441 Mar 25 19:22 obj/Debug/net8.0-android/__Microsoft.Android.Resource.Designer.cs -rw-r--r-- 1 user staff 1094 Mar 25 19:22 obj/Debug/net8.0-android/gxa-8706.AssemblyInfo.cs -rw-r--r-- 1 user staff 407 Mar 25 19:22 obj/Debug/net8.0-android/gxa-8706.GlobalUsings.g.cs In particular, `$(IntermediateOutputPath)generated/*/**.cs` is gone, including `E.Example.cs`! The result of this is that Design-Time builds and "normal" builds "fight" each other, constantly generating and deleting files, slowing down incremental builds. The root of the problem is the `_ClearGeneratedManagedBindings` target: It was designed to clean out the `generated` folder in the case where no binding libraries were present. However, it turns out it was running during a design time build! During design time builds the binding library item groups are not evaluated, so the `_ClearGeneratedManagedBindings` target would run, deleting everything. Fix this by ensuring we only run the `_ClearGeneratedManagedBindings` target in in "standard"/*non*-Design-Time builds.
Fixes: dotnet#8658 Fixes: dotnet#8698 Design-time builds don't play nicely with binding project builds: % dotnet new androidlib % cat > Example.java <<EOF package e; public class Example { public static void e() { } } EOF % dotnet build -p:DesignTimeBuild=true -v:diag After this initial Design-Time build, we have the following generated source code for the binding: % find obj -iname \*.cs | xargs ls -l -rw-r--r-- 1 user staff 197 Mar 25 19:22 obj/Debug/net8.0-android/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs -rw-r--r-- 1 user staff 441 Mar 25 19:22 obj/Debug/net8.0-android/__Microsoft.Android.Resource.Designer.cs -rw-r--r-- 1 user staff 2975 Mar 25 19:22 obj/Debug/net8.0-android/generated/src/E.Example.cs -rw-r--r-- 1 user staff 1518 Mar 25 19:22 obj/Debug/net8.0-android/generated/src/Java.Interop.__TypeRegistrations.cs -rw-r--r-- 1 user staff 696 Mar 25 19:22 obj/Debug/net8.0-android/generated/src/__NamespaceMapping__.cs -rw-r--r-- 1 user staff 1094 Mar 25 19:22 obj/Debug/net8.0-android/gxa-8706.AssemblyInfo.cs -rw-r--r-- 1 user staff 407 Mar 25 19:22 obj/Debug/net8.0-android/gxa-8706.GlobalUsings.g.cs Run a Design-Time build *again*: % dotnet build -p:DesignTimeBuild=true -v:diag …and we're now missing files (?!): % find obj -iname \*.cs | xargs ls -l -rw-r--r-- 1 user staff 197 Mar 25 19:22 obj/Debug/net8.0-android/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs -rw-r--r-- 1 user staff 441 Mar 25 19:22 obj/Debug/net8.0-android/__Microsoft.Android.Resource.Designer.cs -rw-r--r-- 1 user staff 1094 Mar 25 19:22 obj/Debug/net8.0-android/gxa-8706.AssemblyInfo.cs -rw-r--r-- 1 user staff 407 Mar 25 19:22 obj/Debug/net8.0-android/gxa-8706.GlobalUsings.g.cs In particular, `$(IntermediateOutputPath)generated/*/**.cs` is gone, including `E.Example.cs`! The result of this is that Design-Time builds and "normal" builds "fight" each other, constantly generating and deleting files, slowing down incremental builds. The root of the problem is the `_ClearGeneratedManagedBindings` target: It was designed to clean out the `generated` folder in the case where no binding libraries were present. However, it turns out it was running during a design time build! During design time builds the binding library item groups are not evaluated, so the `_ClearGeneratedManagedBindings` target would run, deleting everything. Fix this by ensuring we only run the `_ClearGeneratedManagedBindings` target in in "standard"/*non*-Design-Time builds.
) Fixes: #8658 Fixes: #8698 Design-time builds don't play nicely with binding project builds: % dotnet new androidlib % cat > Example.java <<EOF package e; public class Example { public static void e() { } } EOF % dotnet build -p:DesignTimeBuild=true -v:diag After this initial Design-Time build, we have the following generated source code for the binding: % find obj -iname \*.cs | xargs ls -l -rw-r--r-- 1 user staff 197 Mar 25 19:22 obj/Debug/net8.0-android/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs -rw-r--r-- 1 user staff 441 Mar 25 19:22 obj/Debug/net8.0-android/__Microsoft.Android.Resource.Designer.cs -rw-r--r-- 1 user staff 2975 Mar 25 19:22 obj/Debug/net8.0-android/generated/src/E.Example.cs -rw-r--r-- 1 user staff 1518 Mar 25 19:22 obj/Debug/net8.0-android/generated/src/Java.Interop.__TypeRegistrations.cs -rw-r--r-- 1 user staff 696 Mar 25 19:22 obj/Debug/net8.0-android/generated/src/__NamespaceMapping__.cs -rw-r--r-- 1 user staff 1094 Mar 25 19:22 obj/Debug/net8.0-android/gxa-8706.AssemblyInfo.cs -rw-r--r-- 1 user staff 407 Mar 25 19:22 obj/Debug/net8.0-android/gxa-8706.GlobalUsings.g.cs Run a Design-Time build *again*: % dotnet build -p:DesignTimeBuild=true -v:diag …and we're now missing files (?!): % find obj -iname \*.cs | xargs ls -l -rw-r--r-- 1 user staff 197 Mar 25 19:22 obj/Debug/net8.0-android/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs -rw-r--r-- 1 user staff 441 Mar 25 19:22 obj/Debug/net8.0-android/__Microsoft.Android.Resource.Designer.cs -rw-r--r-- 1 user staff 1094 Mar 25 19:22 obj/Debug/net8.0-android/gxa-8706.AssemblyInfo.cs -rw-r--r-- 1 user staff 407 Mar 25 19:22 obj/Debug/net8.0-android/gxa-8706.GlobalUsings.g.cs In particular, `$(IntermediateOutputPath)generated/*/**.cs` is gone, including `E.Example.cs`! The result of this is that Design-Time builds and "normal" builds "fight" each other, constantly generating and deleting files, slowing down incremental builds. The root of the problem is the `_ClearGeneratedManagedBindings` target: It was designed to clean out the `generated` folder in the case where no binding libraries were present. However, it turns out it was running during a design time build! During design time builds the binding library item groups are not evaluated, so the `_ClearGeneratedManagedBindings` target would run, deleting everything. Fix this by ensuring we only run the `_ClearGeneratedManagedBindings` target in in "standard"/*non*-Design-Time builds. Co-authored-by: Dean Ellis <[email protected]>
Android application type
.NET Android (net7.0-android, net8.0-android, etc.)
Affected platform version
VS2022 17.8.5
Description
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 targetPrepareResources
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
obj\$(Configuration)\$(TargetFramework)\generated\src
obj\$(Configuration)\$(TargetFramework)\generated\src
, the source will be deleted after some delay.Did you find any workaround?
Create a file
Directory.Build.targets
in the Android binding library project directoryAdd to all projects in the solution:
This disables the resource update in the Android binding library
Relevant log output
No response
The text was updated successfully, but these errors were encountered: