rchaganti / DSCResources

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

Update vscodeextension module to support user and system based VS Code installs #26

Open philnach opened 10 months ago

philnach commented 10 months ago

Why is this change being made? This change addresses bug #25, vscodeextension couldn't installing extensions because the module couldn't determine if the user has vscode installed. This change updates the logic for detecting VS Code installs for user and system based installs. Cli and Zip installs aren't addressed in this change.

More information on VS Code install types:

What changed?

  1. Look for user based VS Code installs in HKCU: HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*
  2. Look for system based VS Code installs in HKLM: HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*
  3. Use the path provided in registry as the root path for running code.cmd
  4. Switch from Start-Process to call operator &
  5. Add more verbose logging

I didn't bump the version of the module in this change. I'm assuming that would be another pull request.

Note: when running the DSC to install an extension if you have a user based install you will need to pass PsDscRunAsCredential in order for the DSC to detect VS Code as the DSC runs as system otherwise and doesn't have access to the users regitry hive.

When running the extension you might see the below message. This message is unrelated to the vscodeextension DSC. This appears to be an issue with libraries VS Code leverages see: https://github.com/microsoft/vscode/issues/82524

image

How was the change tested?

  1. Tested user VS Code extension install
  2. Tested system VS Code extension install
  3. Tested without VS Code installed
  4. Tested requesting an install of an already installed extension

Successful execution with the following DSC config (note the use of PsDscRunAsCredential since my install is a user based install):

$SplitParams = @{
    Name = 'vscodeextension'
    ModuleName = 'vscode'
    Method = 'Test'
    Property = @{
        Name = 'ms-azuretools.vscode-bicep'
        Ensure = 'present'
        PsDscRunAsCredential = Get-Credential
    }
}

$SplitParams = @{
    Name = 'vscodeextension'
    ModuleName = 'vscode'
    Method = 'Set'
    Property = @{
        Name = 'ms-azuretools.vscode-bicep'
        Ensure = 'present'
        PsDscRunAsCredential = Get-Credential
    }
}
image