Skip to content

Add TarDirectory and Untar tasks for creating and extracting tar archives#14451

Draft
ViktorHofer with Copilot wants to merge 28 commits into
mainfrom
copilot/create-tar-files-task
Draft

Add TarDirectory and Untar tasks for creating and extracting tar archives#14451
ViktorHofer with Copilot wants to merge 28 commits into
mainfrom
copilot/create-tar-files-task

Conversation

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Adds a TarDirectory inbox task that produces .tar (and optionally .tar.gz) archives from a directory, mirroring the existing ZipDirectory task. Since System.Formats.Tar requires .NET, the task is authored as .NET-only and is unavailable in Visual Studio / MSBuild.exe.

Context

The existing ZipDirectory/Unzip tasks have no tar equivalent. The maintainer discussion settled on shipping this as the first .NET (core)-only inbox task, provided the UsingTask is authored to only bind on the .NET runtime.

Changes Made

  • TarDirectory task (src/Tasks/TarDirectory.cs): creates a tar from SourceDirectory to DestinationFile via System.Formats.Tar. Parameters mirror ZipDirectory: Overwrite, FailIfNotIncremental, plus an optional Compression (None default, or GZip).
    • Per review feedback, an existing destination is not silently deleted — it errors (MSB4322) unless Overwrite="true".
    • Invalid Compression values warn (MSB4324) and fall back to an uncompressed tar. zstd was omitted as it isn't in the BCL.
  • .NET-only gating: TarDirectory.cs compiles only for .NETCoreApp; the UsingTask in Microsoft.Common.tasks is registered with Runtime="NET" and Condition="'$(MSBuildRuntimeType)' == 'Core'".
  • Resources: new strings MSB4321MSB4330 in Strings.resx, synced to all .xlf files.
  • Tests: TarDirectory_Tests.cs (net-only) covering plain/GZip creation, overwrite, and the error/warning paths.
  • Docs: documented the FailIfNotIncremental behavior in documentation/specs/question.md.
<TarDirectory SourceDirectory="$(OutDir)" DestinationFile="package.tar.gz" Compression="GZip" Overwrite="true" />

Testing

Unit tests in TarDirectory_Tests.cs; also verified end-to-end via the bootstrap MSBuild that emitted .tar and .tar.gz archives readable by the system tar utility.

Notes

Two Code Review comments were intentionally left to stay byte-for-byte consistent with ZipDirectory: the "Question" doc-comment terminology, and reusing the Comment resource for question-mode output. Open to diverging if reviewers prefer.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hello @copilot, I noticed that you’re changing an .swr file or any file under src/Package/MSBuild.VSSetup.. Please make sure to validate this change by an experimental VS insertion. This is accomplished by pushing to an exp/* branch, which requires write permissions to this repo.

Copilot AI linked an issue Jul 20, 2026 that may be closed by this pull request
Copilot AI and others added 3 commits July 20, 2026 07:55
Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com>
Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com>
…rammar

Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com>
Copilot AI changed the title [WIP] Add MSBuild task for creating Tar files Add TarDirectory task for creating tar archives Jul 20, 2026
Copilot AI requested a review from ViktorHofer July 20, 2026 08:02
@ViktorHofer

Copy link
Copy Markdown
Member

@copilot looks like the current code falls back to not use gzip when a compression type is passed in that's unrecognized. Given that we will expand this matrix, I would throw an error if an unrecognized compression type is passed in instead of silently falling back to not use gzip.

Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com>

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@copilot looks like the current code falls back to not use gzip when a compression type is passed in that's unrecognized. Given that we will expand this matrix, I would throw an error ...

Done — an unrecognized Compression value now fails the task with error MSB4324 instead of warning and falling back to an uncompressed tar. Updated in the latest commit.

Copilot AI and others added 3 commits July 20, 2026 10:07
Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com>
… in TrimStart

Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com>
Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com>
The stage1 and stage2 CI builds both default their binary log to Build.binlog, so publishing them to the same artifacts location collides. Declare ci/binaryLog/excludeCIBinarylog as first-class parameters, forward them to both stage builds, and pass -binaryLogName Build.stage2.binlog to stage2 when a binlog will actually be produced.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 2a6b38b1-0da7-488f-9938-3ac1051e15e2
Moving the stage 1 artifacts aside relocated its Build.binlog out of the published artifacts/log directory, so CI only published the stage 2 binlog. Copy the stage 1 binlog back as Build.stage1.binlog right after the move (best-effort; skipped when no binlog was produced).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 2a6b38b1-0da7-488f-9938-3ac1051e15e2
Instead of copying just the stage 1 binlog, copy the whole stage 1 log directory back into artifacts/log after the move, so CI publishes all stage 1 logs alongside the stage 2 ones. Runs before the stage 2 build, so it won't clobber stage 2 output.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 2a6b38b1-0da7-488f-9938-3ac1051e15e2
Comment thread src/Tasks/TarDirectory.cs Outdated
Comment thread src/Tasks/TarDirectory.cs Outdated
Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com>
… enum

Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com>
Comment thread src/Tasks/TarDirectory.cs Outdated
@ViktorHofer

Copy link
Copy Markdown
Member

@copilot add an Untar task as well that mimics the Unzip task but goes hand in hand with new TarDirectory task. Add tests and update the PR description.

Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com>

Copilot AI commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@copilot add an Untar task as well that mimics the Unzip task but goes hand in hand with new TarDirectory task. Add tests and update the PR description.

Added the Untar task in the latest commit. It mirrors Unzip: extracts one or more .tar archives to DestinationFolder, with Include/Exclude globs, SkipUnchangedFiles, OverwriteReadOnlyFiles, FailIfNotIncremental, cancellation, tar-slip path protection, and Unix permission restore. Compression (GZip/ZStandard) is auto-detected from the archive's magic bytes, so it handles .tar, .tar.gz, and .tar.zst without a Compression parameter. Like TarDirectory it's .NET-only (Runtime="NET", Condition="'$(MSBuildRuntimeType)' == 'Core'"). Added Untar_Tests.cs (12 tests, all passing) and new resources MSB4331MSB4338 synced to all .xlf files. PR description checklist updated.

@ViktorHofer ViktorHofer changed the title Add TarDirectory task for creating tar archives Add TarDirectory and Untar tasks for creating and extracting tar archives Jul 21, 2026
Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com>
@ViktorHofer

Copy link
Copy Markdown
Member

@copilot fix the build failures

Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com>

Copilot AI commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix the build failures

Fixed the build failure. The CI break was error IDE0052 under -warnaserror: the _enumOutput field in TaskBuilderTestTask was assigned in the EnumParam setter but never read (the tests validate via ParameterSet, and there's already an unrelated EnumOutput property). Removed the unused field and its assignment. Verified src/Build.UnitTests now builds clean with -warnaserror and the TestSetEnumParam* tests pass.

@ViktorHofer

ViktorHofer commented Jul 22, 2026

Copy link
Copy Markdown
Member

@baronfel if you have some time would you taking a look? The tasks are now using the new task types that you mentioned. Not a high priority at all at the moment.

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

Successfully merging this pull request may close these issues.

MSBuild task for creating Tar files

3 participants