rchaganti / DSCResources

Custom DSC resource modules by PowerShell Magazine
http://www.powershellmagazine.com
62 stars 26 forks source link

vscodeextension not working #25

Open HeinvR opened 11 months ago

HeinvR commented 11 months ago

I'm trying to get winget configure set up with the vscode/vscodeextension module.

YAML config:

winget reports that it will install the extension: image

and it also reports the extension as installed after running: image

However when i open vscode my extensions are not there.

I looked at the module directly:

Seems ok: image

I think the problem is in the vscodeextension module, it seems to return true when vscode is not found. Despite vscode being installed on my local machine. image

It seems the regkey which is used to check the vscode version is no longer working: image

Can anyone confirm this is the issue or am i missing something?

philnach commented 11 months ago

@HeinvR, I'm seeing the same output as you when trying your repro steps to install a vscode extension. Looks like the vscodeextension looks in on AMD64: "HKLM:\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*" and "HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*" on x86 (source. Both of those locations aren't correct if you've installed vscode as a none Administrator (https://code.visualstudio.com/docs/setup/windows#_installation).

vscode uses the Inno setup and the uninstall key is in: "HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*"

image

Probably the best way to fix this is to check multiple ways:

  1. Check User install: HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* for "Microsoft Visual Studio Code*"
  2. Check Admin install: HKLM:\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* for "Microsoft Visual Studio Code*"
  3. Check if code command returns a zero result code: 'code --version'
HeinvR commented 11 months ago

Thank you for pointing me in the right direction, @philnach! I did some checks and you are right. It seems that running winget as administrator also installs the users install. Meanwhile I found a solution to installing the extiensions via winget configure. I just used a custom powershell script in my config:

- resource: PSDscResources/Script
  id: Install VScode Extensions
  directives:
    description: Script to install Powershell extensions
    allowPrerelease: true
  settings:
    GetScript: |
      # Not using this at the moment.
    TestScript: |
      return $false
    SetScript: |
      # Ignore deprecation warnings & reload path
      $env:NODE_OPTIONS="--no-deprecation"
      $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") 
      # Extensions to install
      code --install-extension ms-vscode.azure-account
      code --install-extension ms-vscode.PowerShell
      code --install-extension ms-azuretools.vscode-bicep
      code --install-extension ms-python.python