Use linker extensibility to enable better trimming#23512
Conversation
pranavkm
commented
Jun 30, 2020
- Configure TrimmerDefaults=link if unspecified
- Allow Microsoft.AspNetCore.* and Microsoft.Extensions.* packages to be trimmed.
* Configure TrimmerDefaults=link if unspecified * Allow Microsoft.AspNetCore.* and Microsoft.Extensions.* packages to be trimmed.
| using (var file = File.OpenRead(assemblyPath)) | ||
| { | ||
| var peReader = new PEReader(file); | ||
| using var peReader = new PEReader(file); |
|
|
||
| <ManagedAssemblyToLink | ||
| IsTrimmable="true" | ||
| Condition="'%(Extension)' == '.dll' AND ($([System.String]::Copy('%(Filename)').StartsWith('Microsoft.AspNetCore.')) or $([System.String]::Copy('%(Filename)').StartsWith('Microsoft.Extensions.')))" /> |
There was a problem hiding this comment.
(minor) I think there is a way to not duplicate this condition, and instead just use @(_BlazorTypeGranularAssembly) to update these ManagedAssemblyToLink items.
There was a problem hiding this comment.
Is that by removing and adding it? ItemGroup Update doesn't work inside of a target.
| public override bool Execute() | ||
| { | ||
| using var fileStream = File.Create(TrimmerFile.ItemSpec); | ||
| var rootDescriptor = CreateRootDescriptorContents(); |
There was a problem hiding this comment.
Adding the extra package file uncovered an issue with publish incrementalism. We were always writing a new trimmer descriptor which would cause the linker to be non-incremental. The task was updated to use the same pattern as WriteLinesToFile.WriteOnlyWhenDifferent
|
With this change, you should also be able to remove this line: |
|
Thanks @eerhardt. I'll do that as a follow up once I've tested it. We don't have any test coverage for trimmed projects in this branch. |
