Skip to content

Include Copilot CLI runtime assets in PackAsTool packages - #2557

Open
kondv wants to merge 1 commit into
github:mainfrom
kondv:dev/kondv/packastool-runtime-assets
Open

Include Copilot CLI runtime assets in PackAsTool packages#2557
kondv wants to merge 1 commit into
github:mainfrom
kondv:dev/kondv/packastool-runtime-assets

Conversation

@kondv

@kondv kondv commented Sep 7, 2026

Copy link
Copy Markdown

Fixes #2067

Problem

Tool packages are produced from the publish layout, but the SDK registered its Copilot CLI runtime assets only for build output. When a PackAsTool project was packed without rebuilding — the usual CI sequence, and dotnet pack --no-build in general — the resulting package contained no runtimes/<rid>/native payload, and the installed tool failed:

System.InvalidOperationException: Copilot runtime wrapper not found at
'...\tools\net8.0\win-x64\runtimes\win-x64\native\copilot-runtime.exe'.

Change

Register the existing runtime asset items before publish item collection as well as build output, and give them CopyToPublishDirectory, so assets already staged for build output also reach the publish layout the tool package is built from.

The item set, RID selection, download and cache behavior, output paths, and runtime precedence are unchanged. This does not rename the explicit-CLI marker, change stale-file replacement, alter execute permissions, or add CI jobs.

Validation

  • MSBuildTargetsTests — 11 passing on net8.0 and on net472; GitHub.Copilot.Test.Unit — 291 passing
  • dotnet format --verify-no-changes
  • The new test is a real regression test. It asserts every separately registered payload that an installed tool needs: the compatibility alias, copilot-runtime[.exe], runtime.node, the renamed FFI library (copilot_runtime.dll / libcopilot_runtime.*) that RuntimeConnection.ForInProcess() resolves, and a ripgrep asset. Reverting the targets change fails it, and so does dropping CopyToPublishDirectory from any single one of those registrations — each was confirmed by mutating that item alone.
  • End-to-end A/B, each arm packing a locally built SDK, consuming it from an external PackAsTool project outside the repository, then installing the produced tool with dotnet tool install --tool-path and running it with all CLI overrides removed:
    • Unpatched main: 0 runtimes/*/native entries in the tool package; the installed tool crashed with the error above.
    • Patched: 67 native entries including copilot-runtime.exe and runtime.node; the installed tool started the real Copilot CLI from its own packaged assets and completed an RPC round trip.
    • Controls unchanged in both arms: pack -r <rid> and multi-RID RuntimeIdentifiers already packaged the assets before this change, so the defect is specific to packing without rebuilding.

@kondv
kondv requested a review from a team as a code owner September 7, 2026 05:17
Copilot AI balanced review requested due to automatic review settings September 7, 2026 05:17

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.

🟡 Changes recommended

The Windows net472 test build cannot resolve ZipFile without System.IO.Compression.FileSystem.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes PackAsTool publishing so RID-specific packages include usable Copilot CLI runtime assets.

Changes:

  • Publishes runtime assets and compatibility markers.
  • Restores Unix executable permissions.
  • Adds cross-platform packaging, launch tests, and CI coverage.
File summaries
File Description
dotnet/test/Unit/RuntimeWrapperTests.cs Tests CLI precedence and Unix executable restoration.
dotnet/test/Unit/MSBuildTargetsTests.cs Tests RID-specific tool packaging.
dotnet/test/GitHub.Copilot.SDK.Test.csproj Updates test-project compression references, but lacks the required System.IO.Compression.FileSystem reference for net472.
dotnet/src/Client.cs Handles compatibility markers and Unix permissions.
dotnet/src/build/GitHub.Copilot.SDK.targets Publishes RID-specific runtime assets.
.github/workflows/dotnet-sdk-tests.yml Adds Unix .NET 6–8 compatibility coverage.
Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread dotnet/test/GitHub.Copilot.SDK.Test.csproj
@kondv
kondv force-pushed the dev/kondv/packastool-runtime-assets branch 2 times, most recently from e68a27a to 364a173 Compare September 8, 2026 16:50
@kondv kondv changed the title Fix PackAsTool runtime asset publishing Include Copilot CLI runtime assets in PackAsTool packages Sep 8, 2026
@kondv
kondv requested a balanced review from Copilot September 8, 2026 19:00

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.

🟡 Changes recommended

The regression test must verify both required runtime assets.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread dotnet/test/Unit/MSBuildTargetsTests.cs
@kondv
kondv force-pushed the dev/kondv/packastool-runtime-assets branch from 364a173 to dc7e2a2 Compare September 8, 2026 19:44
@kondv
kondv requested a balanced review from Copilot September 8, 2026 20:28

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.

🟡 Changes recommended

The regression test must assert the platform-specific renamed FFI library entry.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread dotnet/test/Unit/MSBuildTargetsTests.cs
@kondv
kondv force-pushed the dev/kondv/packastool-runtime-assets branch from dc7e2a2 to 39d8fa7 Compare September 8, 2026 20:59
@kondv
kondv requested a balanced review from Copilot September 8, 2026 21:18

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.

🟡 Changes recommended

The regression test must use a consistent architecture source; marker-only coverage should also be added.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

dotnet/test/Unit/MSBuildTargetsTests.cs:252

  • Add a marker-only tool-package case. This test passes CopilotCliBinaryPath but also seeds the runtime pair, so .copilot-explicit-cli is swept up by _CopilotRuntimeRootAsset; removing CopyToPublishDirectory from the marker's dedicated registration would still pass. With an explicit binary and no cached pair, CopilotClient relies on that marker to launch the alias instead of requiring copilot-runtime plus runtime.node, so this publish path remains unprotected.
        using var sandbox = MSBuildSandbox.Create(packAsTool: true);
        var preinstalled = sandbox.WritePreinstalledBinary("fake-cli-contents");
        sandbox.WriteRuntimeCacheAsset("prebuilds", GetReleasePlatform(), "runtime.node", "runtime");
        sandbox.WriteRuntimeCacheAsset("prebuilds", GetReleasePlatform(), RuntimeWrapperName, "wrapper");
        sandbox.WriteRuntimeCacheAsset("ripgrep", "bin", GetReleasePlatform(), "rg", "ripgrep");
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread dotnet/test/Unit/MSBuildTargetsTests.cs
@kondv
kondv force-pushed the dev/kondv/packastool-runtime-assets branch from 39d8fa7 to 4eb99cb Compare September 8, 2026 22:06
@kondv
kondv requested a balanced review from Copilot September 9, 2026 01: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.

🟡 Changes recommended

Add package coverage proving the explicit-CLI marker is included when no runtime wrapper pair is seeded.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread dotnet/src/build/GitHub.Copilot.SDK.targets

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.

🟢 Approval recommended

The fix and regression coverage are complete, with no unresolved issues.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@kondv
kondv force-pushed the dev/kondv/packastool-runtime-assets branch from 4eb99cb to e82dcc2 Compare September 9, 2026 03:18
@kondv
kondv requested a balanced review from Copilot September 9, 2026 03:26

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.

🟡 Changes recommended

Published runtime assets removed from later CLI bundles can remain stale and be packed by pack --no-build; cleanup and regression coverage are needed.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread dotnet/src/build/GitHub.Copilot.SDK.targets
Tool packages are produced from the publish layout, but the SDK registered its
Copilot CLI runtime assets only for build output. `dotnet pack --no-build`
therefore produced a tool package with no `runtimes/<rid>/native` payload, and
the installed tool failed with "Copilot runtime wrapper not found".

Register the existing runtime asset items before publish item collection as well
and give them `CopyToPublishDirectory`, so the assets already staged for build
output also reach the publish layout the tool package is built from.
@kondv
kondv force-pushed the dev/kondv/packastool-runtime-assets branch from e82dcc2 to 88fe17b Compare September 9, 2026 19:20
@kondv
kondv requested a balanced review from Copilot September 9, 2026 19:44

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.

🟢 Approval recommended

The publish registration addresses the reported packaging failure and the regression tests cover each independently registered runtime payload.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

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.

PackAsTool: Copilot CLI binary not included in NuGet tool package (cross-platform)

2 participants