Skip to content

Environment variables not resolved in path type settings #6360

Description

@ralish

Relevant area(s)

WinGet CLI

Relevant command(s)

winget settings

Brief description of your issue

WinGet treats settings which take a path as invalid if they contain an environment variable. For example, if .installBehavior.portablePackageUserRoot is set to %LOCALAPPDATA%/Microsoft/WinGet/Packages/ the following behaviour is observed when running these commands:

  • winget:
    Unexpected error while loading settings. Please verify your settings by running the 'settings' command.
    
  • winget settings:
    Unexpected error while loading settings. Please verify your settings by running the 'settings' command.
    The following failures were found validating the settings:
    Invalid field value. Field: .installBehavior.portablePackageUserRoot Value: %LOCALAPPDATA%/Microsoft/WinGet/Packages/
    

This is annoying for a couple of reasons:

  1. Specifying portable paths by using environment variables is impossible (exactly like the default settings do through using %LOCALAPPDATA% and others).
  2. It makes explicitly setting the default values for affected settings impossible.
  3. The default values returned by the JSON schema when adding affected settings is invalid.

As of the latest stable release (v1.29.280) the following settings are impacted:

  • .configureBehavior.defaultModuleRoot
  • .downloadBehavior.defaultDownloadDirectory
  • .installBehavior.portablePackageMachineRoot
  • .installBehavior.portablePackageUserRoot

An additional minor nitpick is running winget settings with a "bad" configuration outputs:

Unexpected error while loading settings. Please verify your settings by running the 'settings' command.

This is redundant given it's telling you to run exactly the command you're running.

Steps to reproduce

Set one or more of the settings referenced in the issue description to an absolute path that includes one or more environment variables. This can simply be the default value provided when adding an affected setting in a configuration that makes use of the published JSON schema.

Expected behavior

Settings which take a path should allow environment variables, with the environment variables being resolved at the time WinGet is invoked. Constraints on the underlying path still apply (e.g. path must be absolute).

Actual behavior

WinGet treats the settings as invalid.

Environment

Output taken from a configuration where all four affected settings have been explicitly set to their default value (consistent with the current JSON schema and the defaults in src/AppInstallerCommonCore/UserSettings.cpp).

Unexpected error while loading settings. Please verify your settings by running the 'settings' command.
    Windows Package Manager v1.29.280
    © 2026 Microsoft. All rights reserved.

Windows: Windows.Desktop v10.0.26200.8655
System Architecture: X64
Package: Microsoft.DesktopAppInstaller v1.29.279.0

WinGet Directories
-------------------------------------------------------------------------------------------------------------------------------
Logs                               %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\DiagOutputDir
User Settings                      %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json
Portable Links Directory (User)    %LOCALAPPDATA%\Microsoft\WinGet\Links
Portable Links Directory (Machine) C:\Program Files\WinGet\Links
Portable Package Root (User)       %LOCALAPPDATA%\Microsoft\WinGet\Packages
Portable Package Root              C:\Program Files\WinGet\Packages
Portable Package Root (x86)        C:\Program Files (x86)\WinGet\Packages
Installer Downloads                %USERPROFILE%\Downloads
Configuration Modules              %LOCALAPPDATA%\Microsoft\WinGet\Configuration\Modules

Links
---------------------------------------------------------------------------
Privacy Statement   https://aka.ms/winget-privacy
License Agreement   https://aka.ms/winget-license
Third Party Notices https://aka.ms/winget-3rdPartyNotice
Homepage            https://aka.ms/winget
Windows Store Terms https://www.microsoft.com/en-us/storedocs/terms-of-sale

Admin Setting                             State
--------------------------------------------------
LocalManifestFiles                        Disabled
BypassCertificatePinningForMicrosoftStore Disabled
InstallerHashOverride                     Disabled
LocalArchiveMalwareScanOverride           Disabled
ProxyCommandLineOptions                   Disabled
ConfigurationProcessorPath                Disabled
DefaultProxy                              Disabled

Metadata

Metadata

Assignees

No one assigned

    Labels

    Command-SettingsIssue-BugIt either shouldn't be doing this or needs an investigation.Needs-TriageIssue needs to be triaged

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions