Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Winget configuration "PSDscResources/Script" error when running "code --install-extension" #3887

Closed
PShipstone opened this issue Nov 14, 2023 · 8 comments
Labels
Area-External Issue outside of winget-cli source Command-Configure Issue related to WinGet Configuration DSC-Resource Issue related to DSC Resources Issue-Bug It either shouldn't be doing this or needs an investigation.
Milestone

Comments

@PShipstone
Copy link

Brief description of your issue

When using Winget configuration, a PSDscResources/Script resource generates an error when running code --install-extension when the extension is not installed. Even though the warning is generated, the vscode extensions do get installed.

Steps to reproduce

  1. Ensure the required VSCode extensions are uninstalled.

  2. Create a YAML DSC file, for example:

# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.2
properties:
  resources:      
    - resource: PSDscResources/Script
      id: myAppConfig
      directives:
        description: Configure My App
        allowPrerelease: true
      settings:
        GetScript: |
          # Your custom PowerShell code to check app configuration
        TestScript: |
          return $false
        SetScript: |
          # PowerShell script commands to install VSCode extensions
          code --install-extension jebbs.plantuml 
          code --install-extension yzhang.markdown-all-in-one      
  configurationVersion: 0.2.0 
  1. Execute WinGet, for example:
winget configuration C:\tmp\dev-machine.dsc.yaml

Expected behavior

The VSCode extentions get installed with no warnings

Actual behavior

The following error is generated

image

Environment

Windows Package Manager (Preview) v1.7.2782-preview
Copyright (c) Microsoft Corporation. All rights reserved.

Windows: Windows.Desktop v10.0.22631.2506
System Architecture: X64
Package: Microsoft.DesktopAppInstaller v1.22.2782.0
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Triage Issue need to be triaged label Nov 14, 2023
@denelon denelon added Issue-Bug It either shouldn't be doing this or needs an investigation. Command-Configure Issue related to WinGet Configuration and removed Needs-Triage Issue need to be triaged labels Nov 14, 2023
@denelon
Copy link
Contributor

denelon commented Nov 14, 2023

I attempted to get a "clean" reproduction using Windows Sandbox. I got this error when running the configuration from a clean state without Visual Studio Code being installed. It looks like the environment variable for the path to "code.exe" hasn't been applied before running the script resource.

3887

If I close and reopen PowerShell and run the same configuration again (with Visual Studio Code now in the path), I do get the error you reported from the image above.

I put all 3 attached files (you'll need to unzip them) in my "C:\Sandbox" directory and then ran winget configure C:\Sandbox\sandbox.dsc.yaml.

Note: You may need to unblock one or more of the files due to the Mark of the Web being applied.

@SteveL-MSFT do you have any ideas on this exception?

3887.dsc.zip

@denelon
Copy link
Contributor

denelon commented Nov 14, 2023

It looks like that is actually coming from VSCode or the extension itself, and not related to the Script resource.

3887-2

@denelon
Copy link
Contributor

denelon commented Nov 14, 2023

Running $LASTEXITCODE returns a 0, so that's just a warning.

@denelon denelon added the Area-External Issue outside of winget-cli source label Nov 14, 2023
@denelon
Copy link
Contributor

denelon commented Nov 14, 2023

I updated the configuration to refresh the environment variables for path, and got it to work on the first run without VSCode installed.

# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.2

###############################################################################
# Attempting to reproduce https://github.com/microsoft/winget-cli/3887        #
############################################################################### 

properties:
  resources:      
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      id: VSCode
      directives:
        description: Install Visual Studio Code
        allowPrerelease: true
      settings:
        id: Microsoft.VisualStudioCode
        source: winget
    - resource: PSDscResources/Script
      dependsOn: 
        - VSCode
      id: myAppConfig
      directives:
        description: Configure My App
        allowPrerelease: true
      settings:
        GetScript: |
          # Your custom PowerShell code to check app configuration
        TestScript: |
          return $false
        SetScript: |
          # PowerShell script commands to install VSCode extensions
          $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
          code --install-extension jebbs.plantuml 
          code --install-extension yzhang.markdown-all-in-one      
  configurationVersion: 0.2.0 

@denelon
Copy link
Contributor

denelon commented Nov 14, 2023

This issue isn't related to WinGet Configuration or the "PSDscResources/Script" DSC Resource, so I'm closing it here. I'd suggest trying to isolate the issue either to VSCode or the extension itself.

@denelon denelon closed this as completed Nov 14, 2023
@denelon denelon added this to the v1.7 Client milestone Nov 14, 2023
@denelon
Copy link
Contributor

denelon commented Nov 14, 2023

Here is a video of the repro (sped up considerably):

Sandbox

@PShipstone
Copy link
Author

PShipstone commented Nov 19, 2023

Thank you Demitrius for looking into this, think it is definitely an issue with VSCode rather than the actual extensions.

Have now got this working using Start-Process -WindowStyle Hidden command 👍

SetScript: |
  # PowerShell script commands to install VSCode extensions
  Start-Process -WindowStyle Hidden code "--install-extension jebbs.plantuml" -Wait
  Start-Process -WindowStyle Hidden code "--install-extension yzhang.markdown-all-in-one" -Wait 

@denelon
Copy link
Contributor

denelon commented Nov 30, 2023

@PShipstone is this for a project configuration at GitHub or just a personal configuration?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-External Issue outside of winget-cli source Command-Configure Issue related to WinGet Configuration DSC-Resource Issue related to DSC Resources Issue-Bug It either shouldn't be doing this or needs an investigation.
Projects
None yet
Development

No branches or pull requests

2 participants