Skip to content
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

Add more options to control trimming behavior #6380

Open
sbomer opened this issue Nov 20, 2020 · 1 comment
Open

Add more options to control trimming behavior #6380

sbomer opened this issue Nov 20, 2020 · 1 comment
Labels

Comments

@sbomer
Copy link
Member

sbomer commented Nov 20, 2020

dotnet/linker#1269 (comment) proposes two new ways to configure trimming:

  • Allow opting into trimming via an ItemGroup, not just via IsTrimmable metadata
  • A property that simplifies opting everything into trimming: TrimAllAssemblies

Currently, the IsTrimmable metadata in MSBuild controls which assemblies are trimmed (see https://docs.microsoft.com/en-us/dotnet/core/deploying/trimming-options#trimmed-assemblies). The metadata can be set on a PackageReference and it will flow to the referenced assemblies, but setting it for individual assemblies requires adding this metadata at the appropriate step in the build with a custom target. The above suggestions would simplify this. For example:

<Target Name="ConfigureTrimming"
        BeforeTargets="PrepareForILLink">
  <ItemGroup>
    <ManagedAssemblyToLink Condition="'%(Filename)' == 'MyAssembly'">
      <IsTrimmable>true</IsTrimmable>
    </ManagedAssemblyToLink>
  </ItemGroup>
</Target>

could be simplified to:

<ItemGroup>
  <TrimmableAssembly Include="MyAssembly" />
</ItemGroup>

It would be important to clarify whether the ItemGroup refers to assemblies by name or by file path (it's more common for ItemGroups to represent files on disk). This is similar to the behavior of TrimmerRootAssembly.

@sbomer
Copy link
Member Author

sbomer commented Nov 20, 2020

Some more comments from @marek-safar on the other thread:

I think it's crucial during the transition period to allow developers to easily experiment with enabling trimming for any assembly. It should be as simple as passing/adding msbuild property. Something like /p:AssemblyTrimModeLink=FSharp.Core (or whatever is best msbuild syntax). We could use the same for an explicit manual override for any assembly.

We could do it via a property by supporting, say, semicolon-delimited assembly names and parsing the property into an ItemGroup - but I'm not sure that's best MSBuild practice. I think making it an ItemGroup would be the best choice, even though it doesn't let you set it on the command-line, to my knowledge.

@rainersigwald do you have any advice on representing a per-assembly option in MSBuild?

sbomer referenced this issue in sbomer/linker Nov 25, 2020
This includes some background on what we added for .NET5, and a proposal for more options in .NET6 :
- An assembly-level attribute to opt into trimming
- Simplified trimming opt-in from the SDK
- Simplified "trim all assemblies" flag

This is a summary of the discussion in dotnet#1269 and https://github.com/dotnet/sdk/issues/14642, and the .NET 5 discussion in dotnet/sdk#12035.
sbomer referenced this issue in dotnet/linker Jan 4, 2021
* Add design doc for trimming opt-in/opt-out

This includes some background on what we added for .NET5, and a proposal for more options in .NET6 :
- An assembly-level attribute to opt into trimming
- Simplified trimming opt-in from the SDK
- Simplified "trim all assemblies" flag

This is a summary of the discussion in #1269 and https://github.com/dotnet/sdk/issues/14642, and the .NET 5 discussion in dotnet/sdk#12035.

* Add existing AssemblyMetadata example

* PR feedback

* Fix typo

* Update docs/design/trimmed-assemblies.md

Co-authored-by: Eric Erhardt <[email protected]>

* Apply suggestions from code review

Co-authored-by: Eric Erhardt <[email protected]>

* PR feedback

* Add notes about opt-out

* Use present tense

* Add more opt-out notes

Co-authored-by: Eric Erhardt <[email protected]>
@sfoslund sfoslund removed their assignment Apr 28, 2021
@sfoslund sfoslund transferred this issue from dotnet/sdk Apr 28, 2021
@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants