Closed rolfbjarne closed 2 years ago
@vitek-karas @sbomer
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.
OK, so I read the source code right then, using TrimMode=copy
and _TrimmerDefaultAction=copy
will get me the behavior I was looking for.
This is related to the change to have TrimMode use two new values:
full
andpartial
: https://github.com/dotnet/linker/pull/2856There 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:
CC @agocke