microsoft / microsoft/winget-cli
For msix installers, winget is not respecting scope=machine preference in settings.json. Only works correctly when "--scope machine" is explicitly passed in the command line.
@ryfu-msft is already working on this.
Since Feb 2, 2023.
- Dominant language
- C++
- Stars
- 26.4k
- Forks
- 1.8k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 15
Description
Brief description of your issue
Winget is not respecting the scope=machine preference in settings.json. But works correctly when --scope machine is explicitly passed in invocation. Specifically, is only using ProvisionPackage (i.e. installing msix system-wide instead) when "--scope machine" is set explicitly.
Steps to reproduce
Update: The Microsoft.PowerShell winget manifest has been updated to not use msix packages for x86 and x64, so the following steps don't reproduce the bug anymore
- Put the following in the settings.json file:
{
"$schema": "https://aka.ms/winget-settings.schema.json",
"installBehavior": {
"preferences": {
"scope": "machine"
}
}
}
- Install an msix without explicitly specifying scope. E.g.
winget install -e Microsoft.PowerShell --verbose
Open the log for the install. Observe the package is registered (i.e. installed for current user) instead of installed system-wide .
- Uninstall the package.
winget uninstall Microsoft.PowerShell
- Install an msix package while explicitly specifying scope E.g.
winget install -e Microsoft.PowerShell --verbose --scope machine
Open the log for the install. Observe the package is provisioned system-wide (search for "ProvisionPackage" in the log)
Example Scenario Where It Matters:
Summary
A sysadmin might use sysprep to boot Windows into auditmode, install software, and then create a generalized image that can be used to provision devices with preinstalled software.
But with winget not respecting scope preference in the settings.json, the software will be installed only for the current user (which is the built-in Administrator account). This not only means that the software won't be installed for new users when the image is generalized, but it also prevents sysprep /generalize from working at all, since sysprep fails if any msix/appx packages are installed for a user but not provisioned for all users.
Steps
- Boot windows into audit mode.
E.g. use an autounattend.xml file including the following:
<settings pass="oobeSystem">
<component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"
xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Reseal>
<Mode>Audit</Mode>
<ForceShutdownNow>false</ForceShutdownNow>
</Reseal>
</component>
</settings>
- Set winget's settings.json to:
{
"$schema": "https://aka.ms/winget-settings.schema.json",
"installBehavior": {
"preferences": {
"scope": "machine"
}
}
}
-
Use winget to install an msix package. E.g.
winget install -e Microsoft.PowerShell -
Generalize the image:
sysprep /generalize /shutdown /oobe
Expected behavior
Sysprep succeeds. You extract a new install.wim and create a usb installer with it. Upon using that installer to create a new windows install, the latest powershell is already installed.
Actual behavior
Sysprep fails. The error log has the following line:
SYSPRP Package Microsoft.PowerShell... was installed for a user, but not provisioned for all users. This package will not function properly in the sysprep image.
This causes sysprep to abort.
Environment
S C:\Users\User\BoxSetup> .\bindeps\winget\wingetdev.exe --info
Windows Package Manager (Preview) v1.5.0-preview
Copyright (c) Microsoft Corporation. All rights reserved.
Windows: Windows.Desktop v10.0.22621.1105
System Architecture: X64
Logs: %TEMP%\WinGet\defaultState
User Settings: %LOCALAPPDATA%\Microsoft\WinGet\Settings\defaultState\settings.json
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.