Skip to content

Deduplicate files using links in mac and linux installers - #52756

Merged
MichaelSimons merged 4 commits into
dotnet:mainfrom
MichaelSimons:linux-mac-installers
Feb 8, 2026
Merged

MichaelSimons merged 4 commits into
dotnet:mainfrom
MichaelSimons:linux-mac-installers

Conversation

@MichaelSimons

@MichaelSimons MichaelSimons commented Jan 30, 2026 •

Copy link
Copy Markdown
Member

Related to: #52183

This PR reduces SDK installer size on Mac and Linux by deduplicating files using symbolic links.

Changes:

  • New CopyPreservingRelativeSymlinks MSBuild task that copies files while preserving relative symlinks (unlike the standard Copy task
    which resolves them)
  • Updated installer build targets to use the new task
  • Added end-to-end tests verifying symlink preservation in .pkg, .deb, and .rpm installers

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.

@MichaelSimons
MichaelSimons force-pushed the linux-mac-installers branch 4 times, most recently from 05b9d37 to 639118c Compare February 4, 2026 17:57
@MichaelSimons
MichaelSimons marked this pull request as ready for review February 4, 2026 22:20
@MichaelSimons
MichaelSimons requested a review from a team February 4, 2026 22:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 CopyPreservingRelativeSymlinks that 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the MSBuild Copy task be updated to support this? Not that we would block on that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy did recently learn the ability to compare content hashes, so this may already be accounted for

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@MichaelSimons MichaelSimons Feb 6, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@MichaelSimons
MichaelSimons enabled auto-merge (squash) February 6, 2026 22:35
@MichaelSimons
MichaelSimons merged commit 1ef20e4 into dotnet:main Feb 8, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants