Repository navigation
Deduplicate files using links in mac and linux installers - #52756
Conversation
05b9d37 to
639118c
Compare
bddf6fa to
33a348d
Compare
There was a problem hiding this comment.
Pull request overview
This PR reduces SDK installer size on Mac and Linux by implementing symbolic link deduplication in installer packages. The primary goal is to preserve symlinks created during layout by the existing DeduplicateAssembliesWithLinks task, preventing them from being resolved back to regular files during the copy to installer staging.
Changes:
- Introduced a new MSBuild task
CopyPreservingRelativeSymlinksthat preserves relative symbolic links during file copy operations - Refactored test infrastructure by extracting MockBuildEngine into a shared helper class
- Added comprehensive unit tests for the new copy task and end-to-end tests validating symlink preservation in .pkg, .deb, and .rpm installers
- Updated installer build targets to use the new task for SDK file copying
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Tasks/sdk-tasks/CopyPreservingRelativeSymlinks.cs | New MSBuild task that copies files while preserving relative symlinks instead of resolving them |
| src/Tasks/sdk-tasks/sdk-tasks.InTree.targets | Registers the new CopyPreservingRelativeSymlinks task for Core runtime |
| src/Layout/redist/targets/GenerateInstallerLayout.targets | Updated to use CopyPreservingRelativeSymlinks for SDK installer layout |
| src/Layout/pkg/dotnet-sdk.proj | Updated to use CopyPreservingRelativeSymlinks for SDK binaries in PublishToDisk target |
| test/sdk-tasks.Tests/MockBuildEngine.cs | Extracted shared test helper from DeduplicateAssembliesWithLinksTests for reuse |
| test/sdk-tasks.Tests/DeduplicateAssembliesWithLinksTests.cs | Removed inline MockBuildEngine class, now uses shared helper |
| test/sdk-tasks.Tests/CopyPreservingRelativeSymlinksTests.cs | Comprehensive unit tests covering symlink preservation, overwrite scenarios, and error cases |
| test/Microsoft.NET.TestFramework/TestContext.cs | Added FindOptionalSdkAcquisitionArtifact method to support platform-specific installer artifact discovery |
| test/EndToEnd.Tests/Utilities/SymbolicLinkHelpers.cs | Refactored to support multiple installer types; renamed ExtractTarGz to ExtractTar for broader compression format support |
| test/EndToEnd.Tests/GivenSdkArchives.cs | Updated to use renamed ExtractTar helper |
| test/EndToEnd.Tests/GivenDotNetLinuxInstallers.cs | Converted to file-scoped namespace; added end-to-end tests for .deb and .rpm symlink preservation |
| test/EndToEnd.Tests/GivenDotNetMacInstallers.cs | New test file validating symlink preservation in .pkg installers |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| /// this task recreates symbolic links at the destination with their original relative targets | ||
| /// instead of resolving and copying the target file contents. | ||
| /// </summary> | ||
| public sealed class CopyPreservingRelativeSymlinks : Task |
There was a problem hiding this comment.
Should the MSBuild Copy task be updated to support this? Not that we would block on that.
There was a problem hiding this comment.
Copy did recently learn the ability to compare content hashes, so this may already be accounted for
There was a problem hiding this comment.
I will defer to Chet on if msbuild Copy should support relative symbolic links. There are a few scenarios to account for which may require additional options.
| } | ||
|
|
||
| // Build a set of normalized source paths for symlink target validation | ||
| var pathComparer = OperatingSystem.IsWindows() ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal; |
There was a problem hiding this comment.
Note that this isn't entirely correct - you can mount case sensitive volumes on Windows and case-insensitive volumes on Linux. I think the default on Mac may have changed from case-sensitive to case-insensitive. And since on Linux you can mount volumes anywhere in the filesystem, you can have a path where part of it is case sensitive and part of it isn't.
I think we never really try to account for all of that though, I don't think there really is a good way to do so.
There was a problem hiding this comment.
I went back and forth on this. I originally had it as OrdinalIgnoreCase as that is how copilot wrote it, but upon review, it suggested this change. I feel as though the chances of the same file being cased differently within the SDK layout is low which is why OrdinalIgnoreCase would work for our current usage. If this were a generic msbuild task, then yes I agree this would need to handle all those scenarios. OrdinalCase is the safest on all platforms. I think I will change it to that.
8e97036 to
240b489
Compare
Related to: #52183
This PR reduces SDK installer size on Mac and Linux by deduplicating files using symbolic links.
Changes:
which resolves them)
How it works:
The existing DeduplicateAssembliesWithLinks task replaces duplicate files with symlinks during layout. Previously, the subsequent Copy step would resolve these symlinks back to regular files. The new task preserves them through to the final installer.