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

How to link only specific assemblies? #2981

Closed
rolfbjarne opened this issue Aug 18, 2022 · 3 comments
Closed

How to link only specific assemblies? #2981

rolfbjarne opened this issue Aug 18, 2022 · 3 comments

Comments

@rolfbjarne
Copy link
Member

This is related to the change to have TrimMode use two new values: full and partial: #2856

There doesn't seem to be an obvious way to only trim specific assemblies anymore.

Previously this could be accomplished by setting TrimMode=copy in the project file, and then selectively change the trim mode for the assemblies I'd like to be trimmed.

If I keep doing this, all assemblies that has opted in to trimmed will be copied, and all assemblies that have not opted in to trimming will be trimmed... which seems quite backwards. Looking at the source code it seems it would work to set _TrimmerDefaultAction=copy to have the assemblies that have not opted in to trimming be copied, but this doesn't seem like the right solution.

Example binlog: build-Mac-20220818_110527.binlog.zip

This project sets TrimMode=copy, but looking at the linker diagnostics some assemblies are linked:

    ILLink: Output action: '    Link' assembly: 'nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb'.
    ILLink: Output action: '    Link' assembly: 'trimmode copy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
    ILLink: Output action: '    Link' assembly: 'nunitlite, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb'.
    ILLink: Output action: '    Save' assembly: 'BundledResources, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
    ILLink: Output action: '    Link' assembly: 'Touch.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

CC @agocke

@akoeplinger
Copy link
Member

@vitek-karas @sbomer

@sbomer
Copy link
Member

sbomer commented Aug 18, 2022

You should be able to do one of the following:

  • If you want to trim assemblies which have [assembly: AssemblyMetadata("IsTrimmable", "True")], as well as specific assemblies that you specify, then set <TrimMode>partial</TrimMode> and use TrimmableAssembly for the individual ones (https://docs.microsoft.com/en-us/dotnet/core/deploying/trimming/trimming-options?pivots=dotnet-7-0#trimming-granularity).

  • If you only want to trim specified assemblies but copy everything else (including those with [assembly: AssemblyMetadata("IsTrimmable", "True")]), then use <_TrimmerDefaultAction>copy</_TrimmerDefaultAction> and <TrimMode>copy</TrimMode> (the latter specifies the behavior for [assembly: IsTrimmable("True")] and <IsTrimmable> assemblies). Then override the action on individual assemblies by setting per-assembly metadata <TrimMode>link</TrimMode>.

The first option is probably what you want, unless you have a specific reason not to trim [assembly: IsTrimmable("True")] assemblies.

@rolfbjarne
Copy link
Member Author

OK, so I read the source code right then, using TrimMode=copy and _TrimmerDefaultAction=copy will get me the behavior I was looking for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants