memstechtips/Winhance · error · Exception

winget install failed with exit code: {exitCode}

Error message

winget install failed with exit code: {exitCode}

What it means

winget was used as a fallback to install the Windows ADK and the winget process exited non-zero. OscdimgToolManager resolves winget via WinGetCliRunner.GetWinGetExePath() (falling back to bare "winget"), runs the install with progress, and throws a plain Exception on any non-zero exit. winget's own stderr is streamed to progress, not included in the exception.

Source

Thrown at src/Winhance.Infrastructure/Features/AdvancedTools/Services/OscdimgToolManager.cs:307

                StatusText = _localization.GetString("Progress_InstallingAdkViaWinget"),
                TerminalOutput = "This may take several minutes"
            });

            var logPath = _fileSystemService.CombinePath(_fileSystemService.GetTempPath(), "adk_winget_install.log");
            var arguments = $"install Microsoft.WindowsADK --exact --silent --accept-package-agreements --accept-source-agreements --override \"/quiet /norestart /features OptionId.DeploymentTools /ceip off\" --log \"{logPath}\"";

            progress?.Report(new TaskProgressDetail
            {
                TerminalOutput = "Starting ADK installation via winget..."
            });

            var wingetExe = WinGetCliRunner.GetWinGetExePath() ?? "winget";
            _logService.LogInformation($"Using winget for ADK install: {wingetExe}");

            var (exitCode, _) = await _dismProcessRunner.RunProcessWithProgressAsync(wingetExe, arguments, progress, cancellationToken).ConfigureAwait(false);
            if (exitCode != 0)
            {
                throw new Exception($"winget install failed with exit code: {exitCode}");
            }

            if (await IsOscdimgAvailableAsync().ConfigureAwait(false))
            {
                _logService.LogInformation("ADK installed via winget and oscdimg.exe found");
                return true;
            }

            _logService.LogError("ADK installed via winget but oscdimg.exe not found");
            return false;
        }
        catch (Exception ex)
        {
            _logService.LogError($"Error installing ADK via winget: {ex.Message}", ex);
            return false;
        }
    }

View on GitHub (pinned to f23d554eb2)

Solutions

  1. Run the same winget command manually in an elevated terminal to see winget's own error text.
  2. Update App Installer from the Microsoft Store to the latest winget, then retry.
  3. Run `winget source reset --force` and `winget source update` to fix a corrupted source list.
  4. Verify the ADK package id is correct for this winget source; fall back to direct adksetup.exe download.
  5. Ensure the process is elevated — machine-scope ADK install requires admin.

Example fix

// before
if (exitCode != 0)
    throw new Exception($"winget install failed with exit code: {exitCode}");

// after: capture winget output and accept the standard agreement flags
var (exitCode, output) = await _dismProcessRunner.RunProcessWithProgressAsync(wingetExe, arguments, progress, cancellationToken).ConfigureAwait(false);
if (exitCode != 0)
    throw new Exception($"winget install failed with exit code {exitCode}. winget output: {output}");
Defensive patterns

Strategy: fallback

Validate before calling

// Probe winget availability and version before relying on it.
bool IsWingetUsable() => !string.IsNullOrEmpty(WinGetCliRunner.GetWinGetExePath());

Try / catch

catch (Exception ex) when (ex.Message.Contains("winget install failed"))
{
    // Fall back to direct adksetup.exe download (InstallA dkAsync) or the Microsoft.OSCDIMG winget package.
}

Prevention

When it happens

Trigger: InstallA dkViaWingetAsync runs winget with the ADK package id and RunProcessWithProgressAsync returns exitCode != 0. winget fails for: package not found in configured sources, App Installer out of date, network/source unreachable, user lacks privileges for machine-scope install, or the package needs a newer OS.

Common situations: winget (App Installer) is an old version that does not support the requested args/MSStore source. The machine is behind a proxy winget cannot use. Source agreements were not accepted (--accept-* flags may be missing depending on winget version). winget is not installed at all so the fallback path `winget` resolves to nothing useful.

Related errors


AI-assisted analysis of memstechtips/Winhance@f23d554eb2 (2026-08-13). Data as JSON: /api/errors/9175b045628f4be7. Report an issue: GitHub.