Open sbomer opened 2 years ago
It would be good to have a motivating use case for this. I'm having a hard time coming up with an example of a scenario where library is reflecting on itself in an unpredictable way (the Azure issue doesn't seem to actually have one either).
The more typical scenario for trimming unfriendly code is libraries that reflect on code outside of their own assembly because they cannot reference it statically (think: Newtonsoft, Autofac). Such attribute wouldn't be useful for them, unless it disables trimming for the whole app. We probably don't want to give libraries such power.
We considered supporting
[AssemblyMetadata("IsTrimmable", "False")]
, but decided against it at the time because overuse of this attribute would potentially prevent trimming in situations where only a trim-friendly part of a library is used. Now that the trimming defaults have changed to trim-by-default, we might want to reconsider.We also changed the MSBuild logic so that setting MSBuild metadata
<IsTrimmable>false</IsTrimmable>
on an individual assembly (in theManagedAssemblyToLink
itemgroup) would give it thecopy
action - see https://github.com/dotnet/linker/pull/2856#discussion_r907551819.Personally I still don't see much value in this, but I opened this to track the discussion since it came up in https://github.com/Azure/azure-sdk-for-net/issues/24238.