xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.63k stars 1.87k forks source link

[Bug] On demand resources tags are not working from Visual Studio #15692

Open snehaljadhavwipro opened 1 year ago

snehaljadhavwipro commented 1 year ago

Description

We are trying to use On Demand Resources in Forms app for iOS to reduce the initial download size of the app. We are trying to apply on demand feature to some images and font files(.ttc and .otf) by applying on demand resource tag from Visual Studio. However, the On Demand tags are not working as expected.

Steps to Reproduce

Scenario 1

From Visual Studio: Image in the Resource folder

  1. Create folder for Resources in Xamarin.iOS
  2. Add image in the resource folder
  3. Right click on the image and add On-Demand tag as "testtag"
  4. Use the same image in Xamarin forms
  5. Observe if image is displayed or not

    Expected Behavior

    Image should not get displayed until we explicitly fetch the resource by calling BeginAccessingResourcesAsync() method on the tag

    Actual Behavior

    Image still gets displayed without explicitly fetching the resource by calling BeginAccessingResourcesAsync() method on the tag

Scenario 2

From Xcode: Image in the Resource folder

  1. Create folder for Resources in Xamarin.iOS
  2. Add image in the resource folder
3. Open Resources folder in Xcode (Click xcassets)
  3. Right click on the image and add On-Demand tag as "testtag"
  4. Use the same image in Xamarin forms
  5. Observe if image is displayed or not Xcode will open to edit assets

    Expected Behavior

    Image should not get displayed until we explicitly fetch the resource by calling BeginAccessingResourcesAsync() method on the tag

    Actual Behavior

    Image still gets displayed without explicitly fetching the resource by calling BeginAccessingResourcesAsync() method on the tag. It means on demand tag is not getting applied.


From Xcode: Image in the xcasset folder

Scenario 3

  1. Create folder for Resources in Xamarin.iOS
  2. Create folder for Images.xcassets in Resources
  3. When we double click Images.xcassets in visual studio it will prompt us to open it in Xcode to edit
  4. Open it in Xcode
  5. Add image dataset in the images.xcassets from resource folder
  6. Right click on the image and add On-Demand tag as "testtag"
  7. Use the same image in Xamarin forms
  8. Observe if image is displayed or not

    Expected Behavior

    Image should not get displayed until we explicitly fetch the resource by calling BeginAccessingResourcesAsync() method on the tag

    Actual Behavior

    Image is displayed.



6. Double click on Project.iOS from Visual Studio

  1. Click on On Demand Resources
  2. Add testtag in Prefetch order in debug setting
  3. Run the Project and Observe image


    Expected Behavior

    Image should be visible as we have added the associated tag in Prefetch.


    Actual Behavior

    Image is not visible.

Basic Information

Environment

Show/Hide Visual Studio info ``` Visual Studio Enterprise 2022 for Mac Version 17.3.2 (build 24) Installation UUID: 964bf807-fc51-4082-8bc3-a75fa19b6088 Runtime .NET 6.0.5 (64-bit) Architecture: X64 Roslyn (Language Service) 4.3.0-3.22312.2+52adfb8b2dc71ed4278debcf13960f2116868608 NuGet Version: 6.2.1.2 .NET SDK (x64) SDK: /usr/local/share/dotnet/sdk/6.0.400/Sdks SDK Versions: 6.0.400 5.0.405 3.1.422 3.1.416 MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks .NET Runtime (x64) Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 6.0.8 5.0.14 3.1.28 3.1.22 Xamarin.Profiler Version: 1.8.0.19 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler Updater Version: 11 Xamarin.Android Version: 13.0.0.0 (Visual Studio Enterprise) Commit: xamarin-android/d17-3/030cd63 Android SDK: /Users/snehaljadhav/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: 12.1 (API level 32) 12.0 (API level 31) 11.0 (API level 30) 10.0 (API level 29) 9.0 (API level 28) 13.0 (API level 33) SDK Command-line Tools Version: 7.0 SDK Platform Tools Version: 33.0.2 SDK Build Tools Version: 33.0.0 Build Information: Mono: dffa5ab Java.Interop: xamarin/java.interop/d17-3@7716ae53 SQLite: xamarin/sqlite/3.38.5@df4deab Xamarin.Android Tools: xamarin/xamarin-android-tools/main@14076a6 Microsoft Build of OpenJDK Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk 11.0.12 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL Eclipse Temurin JDK Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk 1.8.0.302 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL Android SDK Manager Version: 17.3.0.23 Hash: 965bf40 Branch: remotes/origin/d17-3 Build date: 2022-08-18 19:06:26 UTC Android Device Manager Version: 0.0.0.1169 Hash: fafb1d5 Branch: fafb1d5 Build date: 2022-08-18 19:06:26 UTC Apple Developer Tools Xcode 13.4.1 (20504) Build 13F100 Xamarin.Mac Version: 8.12.0.2 (Visual Studio Enterprise) Hash: 87f98a75e Branch: d17-3 Build date: 2022-07-25 20:18:54-0400 Xamarin.iOS Version: 15.12.0.2 (Visual Studio Enterprise) Hash: 87f98a75e Branch: d17-3 Build date: 2022-07-25 20:18:55-0400 Xamarin Designer Version: 17.3.0.208 Hash: 0de472ea0 Branch: remotes/origin/d17-3 Build date: 2022-08-18 19:06:21 UTC Build Information Release ID: 1703020024 Git revision: c1a3681e7dfad26a867f37f6666da40621931798 Build date: 2022-08-18 19:04:12+00 Build branch: release-17.3 Build lane: release-17.3 Operating System Mac OS X 12.2.1 Darwin 21.3.0 Darwin Kernel Version 21.3.0 Wed Jan 5 21:37:58 PST 2022 root:xnu-8019.80.24~20/RELEASE_X86_64 x86_64 ```

Build Logs

Workaround

Work around is for images present in xcassets, tags can be added from xcode and use on demand feature. However, tags can not be added for font files or images present outside xcassets. Prefetch tag order feature of On Demand can not be used for even for images present in xcassets.