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

Error installing PowerShell module using PSResourceGet #3501

Open
mgreenegit opened this issue Aug 4, 2023 · 1 comment
Open

Error installing PowerShell module using PSResourceGet #3501

mgreenegit opened this issue Aug 4, 2023 · 1 comment
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation. PowerShell Issue related to WinGet PowerShell Module or cmdlet

Comments

@mgreenegit
Copy link
Member

Brief description of your issue

Error occurs when installing the module using install-psresource.

Steps to reproduce

install-psresource Microsoft.WinGet.Client -TrustRepository

Expected behavior

Install module without error (as is the case for PowerShellGet/Install-Module).

Actual behavior

Install-PSResource: At line:69 char:21

  • NestedModules = if ($env:PROCESSOR_ARCHITECTURE -like 'x86')
  •                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

A variable that cannot be referenced in restricted language mode or a Data section is being referenced. Variables that can be referenced include the following: $PSCulture, $PSUICulture, $true, $false, $null, $PSEdition, $PSScriptRoot.

Environment

Pwsh7.4p4
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Triage Issue need to be triaged label Aug 4, 2023
@denelon denelon added Issue-Bug It either shouldn't be doing this or needs an investigation. PowerShell Issue related to WinGet PowerShell Module or cmdlet and removed Needs-Triage Issue need to be triaged labels Aug 4, 2023
msftrubengu added a commit that referenced this issue Oct 24, 2023
Move to Any CPU projects
Moves Microsoft.WinGet.Client.Cmdlet and Microsoft.WinGet.Client.Engine to be Any CPU platform binaries. This is in preparation of PSResourceGet (aka PowerShellGet v3) release and addresses #3501 as $env:PROCESSOR_ARCHITECTURE is not an allowed variable in a psd1.

Handle server disconnection
Before, we had a static PackageManager object for OOP calls. In the scenario where winget is upgraded, this object will be disconnected, and one would have to close its PowerShell 7 session and open a new one to keep using the cmdlets. This PR creates a wrapper that handles disconnections.

Windows PowerShell support
Correctly throw NotSupported exception for cmdlets that use winget's COM APIs. For this I had to track down all the types being loaded per command and make sure they get loaded after the constructor of each one. This resulted in some weird cases that I need to pass a string instead of an enum in the virtual methods of some base classes.
Fix issue where Microsoft.Win32.Registry.dll was missing.
Add Pester tests specifically for Windows PowerShell

Expected Layout
Microsoft.WinGet.Client\
	Format.ps1xml
	Microsoft.WinGet.Client.psd1
	net48\
		Microsoft.Win32.Registry.dll
		Microsoft.WinGet.Client.Cmdlets.dll
		Microsoft.WinGet.Client.Engine.dll
		Microsoft.WinGet.SharedLib.dll
		Newtonsoft.Json.dll
		Octokit.dll
	net6.0-windows10.0.22000.0\
		Microsoft.WinGet.Client.Cmdlets.dll
		DirectDependencies\
			Microsoft.WinGet.Client.Engine.dll
		SharedDependencies\
			Microsoft.Windows.SDK.NET.dll
			Microsoft.WinGet.SharedLib.dll
			Newtonsoft.Json.dll
			Octokit.dll
			WinRT.Runtime.dll
			x64\
				Microsoft.Management.Deployment.dll
				Microsoft.Management.Deployment.winmd
				WindowsPackageManager.dll
				winrtact.dll
			x86\
				Microsoft.Management.Deployment.dll
				Microsoft.Management.Deployment.winmd
				WindowsPackageManager.dll
				winrtact.dll
I didn't add the native binaries in the Windows PowerShell because they will never be loaded.

Additional changes:

Remove unnecessary AnyCpu build in AppInstallerCLI.sln
Fully remove Microsoft.WinGet.Client tests from AppInstallerCLIE2ETests in favor of Pester tests.
Improve Initialize-LocalWinGetModules.ps1 for local development. You can now specify which module to initialize.
JohnMcPMS pushed a commit to JohnMcPMS/winget-cli that referenced this issue Nov 8, 2023
Move to Any CPU projects
Moves Microsoft.WinGet.Client.Cmdlet and Microsoft.WinGet.Client.Engine to be Any CPU platform binaries. This is in preparation of PSResourceGet (aka PowerShellGet v3) release and addresses microsoft#3501 as $env:PROCESSOR_ARCHITECTURE is not an allowed variable in a psd1.

Handle server disconnection
Before, we had a static PackageManager object for OOP calls. In the scenario where winget is upgraded, this object will be disconnected, and one would have to close its PowerShell 7 session and open a new one to keep using the cmdlets. This PR creates a wrapper that handles disconnections.

Windows PowerShell support
Correctly throw NotSupported exception for cmdlets that use winget's COM APIs. For this I had to track down all the types being loaded per command and make sure they get loaded after the constructor of each one. This resulted in some weird cases that I need to pass a string instead of an enum in the virtual methods of some base classes.
Fix issue where Microsoft.Win32.Registry.dll was missing.
Add Pester tests specifically for Windows PowerShell

Expected Layout
Microsoft.WinGet.Client\
	Format.ps1xml
	Microsoft.WinGet.Client.psd1
	net48\
		Microsoft.Win32.Registry.dll
		Microsoft.WinGet.Client.Cmdlets.dll
		Microsoft.WinGet.Client.Engine.dll
		Microsoft.WinGet.SharedLib.dll
		Newtonsoft.Json.dll
		Octokit.dll
	net6.0-windows10.0.22000.0\
		Microsoft.WinGet.Client.Cmdlets.dll
		DirectDependencies\
			Microsoft.WinGet.Client.Engine.dll
		SharedDependencies\
			Microsoft.Windows.SDK.NET.dll
			Microsoft.WinGet.SharedLib.dll
			Newtonsoft.Json.dll
			Octokit.dll
			WinRT.Runtime.dll
			x64\
				Microsoft.Management.Deployment.dll
				Microsoft.Management.Deployment.winmd
				WindowsPackageManager.dll
				winrtact.dll
			x86\
				Microsoft.Management.Deployment.dll
				Microsoft.Management.Deployment.winmd
				WindowsPackageManager.dll
				winrtact.dll
I didn't add the native binaries in the Windows PowerShell because they will never be loaded.

Additional changes:

Remove unnecessary AnyCpu build in AppInstallerCLI.sln
Fully remove Microsoft.WinGet.Client tests from AppInstallerCLIE2ETests in favor of Pester tests.
Improve Initialize-LocalWinGetModules.ps1 for local development. You can now specify which module to initialize.
@kilasuit
Copy link
Contributor

Seem this can be closed as I can't replicate this @denelon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation. PowerShell Issue related to WinGet PowerShell Module or cmdlet
Projects
None yet
Development

No branches or pull requests

3 participants