-
Notifications
You must be signed in to change notification settings - Fork 511
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
Linker does not remove unused assemblies if they are referenced in NSObject subclasses #15723
Comments
This is expected behavior: we tell the linker to not remove any Admittedly it might be possible to scan storyboards to figure out which classes they need, and tell the linker to keep those, but this would likely be a rather big task to implement, and probably won't happen any time soon (also there might be other reasons to keep |
Keeping open in case we decide to look into detecting any NSObject-subclass-usage from storyboards. |
Could it be possible to opt-out of the |
There's no official way to do it, but there might be a really hacky way to do it: rename your assembly to xamarin-macios/tools/linker/MarkNSObjects.cs Lines 146 to 151 in b462bfd
and we should skip preserving Of course do this at your own risk (and it won't work if you're using Xamarin.Forms)... but I'm also curious about what you find out if you do it :) |
I enthusiastically tried this and got a build with a teeny tiny difference in my "Xamarin.Forms.Platform.iOS" assembly (and it worked fine). From that I remembered that what I'd really want is to have this behaviour applied to one of my dependencies (ReactiveUI, which has many 'Reactive' subclasses of UIKit pieces, many of which I don't use), not the core project. Renaming that one will be a bit more involved I think :') |
It shouldn't be too hard to make this an opt-out behavior (at your own risk), but it might take some time until it reaches a stable release. Are you building a .NET app or a legacy Xamarin.iOS app? |
… assemblies. Fixes xamarin#15723. We mark all types that derive from NSObject when we find them in user assemblies, so that these types may be used in storyboards (where the linker can't see them), without having to go through hoops to make sure the linker doesn't remove these types (which would make the storyboard fail to load, because it would reference types that were linked away). However, not everybody uses storyboards, so in some cases it may make sense to link away as much as possible, so make it opt-in to skip this custom marking. This is an experimental feature, and will break at least some apps. It may break most apps, but if someone wants to try it out, they're welcome! Fixes xamarin#15723.
… assemblies. Fixes xamarin#15723. We mark all types that derive from NSObject when we find them in user assemblies, so that these types may be used in storyboards (where the linker can't see them), without having to go through hoops to make sure the linker doesn't remove these types (which would make the storyboard fail to load, because it would reference types that were linked away). However, not everybody uses storyboards, so in some cases it may make sense to link away as much as possible, so make it opt-in to skip this custom marking. This is an experimental feature, and will break at least some apps. It may break most apps, but if someone wants to try it out, they're welcome! Fixes xamarin#15723.
This has been implemented now (as an opt-in), and will be included in .NET 8. It can be turned on by passing <PropertyGroup>
<MtouchExtraArgs>--skip-marking-nsobjects-in-user-assemblies=true</MtouchExtraArgs>
</PropertyGroup> |
… assemblies. Fixes #15723. (#17949) We mark all types that derive from NSObject when we find them in user assemblies, so that these types may be used in storyboards (where the linker can't see them), without having to go through hoops to make sure the linker doesn't remove these types (which would make the storyboard fail to load, because it would reference types that were linked away). However, not everybody uses storyboards, so in some cases it may make sense to link away as much as possible, so make it opt-in to skip this custom marking. This is an experimental feature, and will break at least some apps. It may break most apps, but if someone wants to try it out, they're welcome! It can be turned on by passing `--skip-marking-nsobjects-in-user-assemblies=true` to mtouch/mmp: ```xml <PropertyGroup> <MtouchExtraArgs>--skip-marking-nsobjects-in-user-assemblies=true</MtouchExtraArgs> </PropertyGroup> ``` Fixes #15723.
The linked does not correctly remove unused assemblies / methods when those calls are located in a NSObject subclass.
This increases the built .ipa unnecessarily.
Steps to Reproduce
test
folderdotnet publish -c Release
/test/bin/Release/net6.0-ios/ios-arm64/publish/test.ipa
to azip
file and inspectExpected Behavior
The package does not contain System.Text.Json.dll & others
Actual Behavior
The package does not contain System.Text.Json.dll & others
Additional notes
The linker also correctly removes the assembly when the
UnusedClass
is commented out or when theUnusedClass
does not extendNSObject
.Environment
Version information
Example Project (If Possible)
test.zip
The text was updated successfully, but these errors were encountered: