microsoft / winget-cli

WinGet is the Windows Package Manager. This project includes a CLI (Command Line Interface), PowerShell modules, and a COM (Component Object Model) API (Application Programming Interface).
https://learn.microsoft.com/windows/package-manager/
MIT License
23.14k stars 1.44k forks source link

winget configure fails when calling WindowsOptionalFeature DSC Resource #4264

Open jcwalker opened 7 months ago

jcwalker commented 7 months ago

Brief description of your issue

When a winget configuration calls the DSC resource PSDscResources/WindowsOptionalFeature it will error with with message Class not registered

Steps to reproduce

Author a configuration with the following resource:

  - resource: PSDscResources/WindowsOptionalFeature
    id: removeWindowsMediaPlayer
    directives:
      description: Uninstall Windows Media removeWindowsMediaPlayer
    settings:
      name: WindowsMediaPlayer
      ensure: Absent 

Expected behavior

Configuration succeeds and the optional feature is removed.

Actual behavior

Errors with Class not registered

image

From the winget logs this is happening on line 286 of the DSC resource image

image

When running the same command in PowerShell the command succeeds without error: image

Is winget using a different version of Dism than the PowerShell module is?

This happens on Windows 10 and Windows 11, PowerShell version 5.1 or 7.4

Environment

Windows Package Manager v1.7.10582
Windows: Windows.Desktop v10.0.22631.3296
System Architecture: X64
Package: Microsoft.DesktopAppInstaller v1.22.10582.0
github-actions[bot] commented 7 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

denelon commented 7 months ago

I ran into this same problem with the Windows Sandbox. It looks like it's happening to the way the DISM APIs are being called. We recently refactored our WinGet dependency feature to call DISM directly.

I did find a bit of a workaround by using the Microsoft.WinGet.Configuration module (requires PowerShell 7).

https://github.com/microsoft/devhome/tree/main/docs/sampleConfigurations/DscResources/Microsoft.WindowsSandbox.DSC#microsoftwindowssandboxdsc

jcwalker commented 7 months ago

@denelon thanks for the quick reply! I can confirm that workaround work.

Trenly commented 7 months ago
phueac commented 6 months ago

I am getting the same error when using this YAML:

properties:
  resources:
    - resource: PSDscResources/WindowsOptionalFeature
      settings:
        name: VirtualMachinePlatform
        ensure: Present

Error in the log file: 2024-04-02 15:56:41.341 [CONF] Microsoft.Management.Configuration.Processor.Exceptions.InvokeDscResourceException: Failed when calling `Test` for resource: WindowsOptionalFeature [PSDscResources] Message: 'Class not registered ' It appears @denelon's workaround does work, but using winget configure to install PowerShell 7 on a fresh machine beforehand is a bit of a pain.

As a side note, it seems that installing and setting up WSL is a very common use case for winget configure, which currently requires multiple steps in the YAML file to get working (enable Windows Virtual Machine Platform, install WSL, install desired Linux distro). It would be great if there was a DSC module which just does all this for you.