{"record":{"id":"9175b045628f4be7","repo":"memstechtips/Winhance","slug":"winget-install-failed-with-exit-code-exitcode","errorCode":null,"errorMessage":"winget install failed with exit code: {exitCode}","messagePattern":"winget install failed with exit code: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Winhance.Infrastructure/Features/AdvancedTools/Services/OscdimgToolManager.cs","lineNumber":307,"sourceCode":"                StatusText = _localization.GetString(\"Progress_InstallingAdkViaWinget\"),\r\n                TerminalOutput = \"This may take several minutes\"\r\n            });\r\n\r\n            var logPath = _fileSystemService.CombinePath(_fileSystemService.GetTempPath(), \"adk_winget_install.log\");\r\n            var arguments = $\"install Microsoft.WindowsADK --exact --silent --accept-package-agreements --accept-source-agreements --override \\\"/quiet /norestart /features OptionId.DeploymentTools /ceip off\\\" --log \\\"{logPath}\\\"\";\r\n\r\n            progress?.Report(new TaskProgressDetail\r\n            {\r\n                TerminalOutput = \"Starting ADK installation via winget...\"\r\n            });\r\n\r\n            var wingetExe = WinGetCliRunner.GetWinGetExePath() ?? \"winget\";\r\n            _logService.LogInformation($\"Using winget for ADK install: {wingetExe}\");\r\n\r\n            var (exitCode, _) = await _dismProcessRunner.RunProcessWithProgressAsync(wingetExe, arguments, progress, cancellationToken).ConfigureAwait(false);\r\n            if (exitCode != 0)\r\n            {\r\n                throw new Exception($\"winget install failed with exit code: {exitCode}\");\r\n            }\r\n\r\n            if (await IsOscdimgAvailableAsync().ConfigureAwait(false))\r\n            {\r\n                _logService.LogInformation(\"ADK installed via winget and oscdimg.exe found\");\r\n                return true;\r\n            }\r\n\r\n            _logService.LogError(\"ADK installed via winget but oscdimg.exe not found\");\r\n            return false;\r\n        }\r\n        catch (Exception ex)\r\n        {\r\n            _logService.LogError($\"Error installing ADK via winget: {ex.Message}\", ex);\r\n            return false;\r\n        }\r\n    }\r\n\r","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/memstechtips/Winhance/blob/f23d554eb2d6400b1827bcc46b91294ffa53fbc9/src/Winhance.Infrastructure/Features/AdvancedTools/Services/OscdimgToolManager.cs#L289-L325","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run the same winget command manually in an elevated terminal to see winget's own error text.","Update App Installer from the Microsoft Store to the latest winget, then retry.","Run `winget source reset --force` and `winget source update` to fix a corrupted source list.","Verify the ADK package id is correct for this winget source; fall back to direct adksetup.exe download.","Ensure the process is elevated — machine-scope ADK install requires admin."],"exampleFix":"// before\nif (exitCode != 0)\n    throw new Exception($\"winget install failed with exit code: {exitCode}\");\n\n// after: capture winget output and accept the standard agreement flags\nvar (exitCode, output) = await _dismProcessRunner.RunProcessWithProgressAsync(wingetExe, arguments, progress, cancellationToken).ConfigureAwait(false);\nif (exitCode != 0)\n    throw new Exception($\"winget install failed with exit code {exitCode}. winget output: {output}\");","handlingStrategy":"fallback","validationCode":"// Probe winget availability and version before relying on it.\nbool IsWingetUsable() => !string.IsNullOrEmpty(WinGetCliRunner.GetWinGetExePath());","typeGuard":null,"tryCatchPattern":"catch (Exception ex) when (ex.Message.Contains(\"winget install failed\"))\n{\n    // Fall back to direct adksetup.exe download (InstallA dkAsync) or the Microsoft.OSCDIMG winget package.\n}","preventionTips":["Update App Installer (winget) from the Microsoft Store before relying on the winget path.","Run elevated for machine-scope installs.","Have a non-winget fallback (direct ADK download) ready when winget is unavailable."],"tags":["installer","winget","external-process","windows","prerequisite","network"],"backgroundTag":null,"analyzedSha":"f23d554eb2d6400b1827bcc46b91294ffa53fbc9","analyzedAt":"2026-08-13T17:55:20.922Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}