Skip to content

fix(solution): use ArgumentList for PAC CLI invocation to fix stray quote on --packagetype - #1529

Draft
rnwood with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-compress-dataversesolutionfile
Draft

fix(solution): use ArgumentList for PAC CLI invocation to fix stray quote on --packagetype#1529
rnwood with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-compress-dataversesolutionfile

Conversation

Copilot AI commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Compress-DataverseSolutionFile -PackageType Managed fails because PAC CLI receives Managed" (trailing quote) as the --packagetype value, causing an invalid-argument error.

Root Cause

Arguments were built as a single manually-quoted string:

// Fragile — trailing backslash in a directory path breaks Windows arg parsing
var args = $"solution pack --zipfile \"{resolvedOutputPath}\" --folder \"{workingPath}\" --packagetype {PackageType}";

When workingPath ends with \, the sequence "D:\folder\" contains \" which Windows CommandLineToArgvW treats as an escaped quote — the closing " is never seen as a terminator, and --packagetype Managed is absorbed into the folder value. When PAC CLI is invoked through a .cmd wrapper this quoting interaction produces a stray " appended to the final token (Managed").

Changes Made

  • PacCliHelper.ExecutePacCliWithOutput signature changed to accept string[] of individual arguments instead of a pre-quoted string string
    • net8.0: populates ProcessStartInfo.ArgumentList — the runtime handles all escaping
    • net462: builds a properly-escaped Arguments string via EscapeWindowsArgument, which correctly doubles trailing backslashes before the closing "
  • CompressDataverseSolutionFileCmdlet, ExpandDataverseSolutionFileCmdlet, ImportDataverseSolutionCmdlet, ExportDataverseSolutionCmdlet updated to pass individual unquoted argument tokens
// After — each value passed as a discrete, unescaped token
var pacArgs = new[]
{
    "solution", "pack",
    "--zipfile", resolvedOutputPath,
    "--folder", workingPath,
    "--packagetype", PackageType.ToString()
};
var result = PacCliHelper.ExecutePacCliWithOutput(this, pacArgs);

Testing

  • Unit tests pass
  • E2E tests pass (if applicable)
  • Manual testing completed

Checklist

  • Code follows the project's coding conventions
  • Documentation updated (if needed)
  • Tests added/updated (if needed)
  • PR title uses conventional commit format (REQUIRED)

… quote in --packagetype value

Fixes #1528

Passing all PAC CLI arguments as individually-escaped values via
ProcessStartInfo.ArgumentList (net8.0) and a proper Windows
CommandLineToArgvW-compatible escaping helper (net462) instead of
building a single manually-quoted argument string.

The previous approach was fragile: a path ending with a backslash
(e.g. `--folder "D:\folder\"`) causes Windows argument parsing to
treat `\"` as an escaped quote, so the closing `"` for that argument
is never seen and the subsequent `--packagetype Managed` token is
consumed as part of the folder value. When the PAC CLI is a .cmd
wrapper the quoting interaction can produce a stray trailing `"`
on the `--packagetype` value (`Managed"`), causing the error shown in
the bug report.
Copilot AI changed the title [WIP] Fix Compress-DataverseSolutionFile argument value error fix(solution): use ArgumentList for PAC CLI invocation to fix stray quote on --packagetype Jun 15, 2026
Copilot AI requested a review from rnwood June 15, 2026 11:40
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.

2 participants