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
Allow Microsoft.WinGet.Client to run in any PowerShell session running as system #3816
Conversation
|
||
/// <summary> | ||
/// Gets or sets how to match against package fields. | ||
/// </summary> | ||
protected string[] Query { get; set; } | ||
#pragma warning disable SA1011 // Closing square brackets should be spaced correctly | ||
protected string[]? Query { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Academic question: Does string?[]
mean a non-null array of nullable strings, while string[]?
means a nullable array of non-null strings? If so, then string?[]?
is a lovingly confusing type name 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. There's another place where I needed a non-nullable array with nullable objects, so it was object?[]
This PR adds support for running the Microsoft.WinGet.Client module in system context without the need to start pwsh.exe -MTA. Running as MTA is required using inproc Microsoft.Management.Deployment.
If the module is running inproc and the current thread is not an MTA, it will create a new MTA thread and execute there. Otherwise, non inproc or already an MTA will use the current thread.
This was done by sharing AsyncCommand (renamed to PowerShellCmdlet) from Microsoft.WinGet.Configuration. Originally, I wanted to create a new shared lib, but decided to just share the files between the projects.
All cmdlets must inherit from PowerShellCmdlet. All cmdlets that use Microsoft.Management.Deployment must inherit ManagementDeploymentCommand and use Execute at the command engine entry point. As a safe mechanism, if any call to PackageManagerWrapper will verify the thread is not an STA if running inproc and fail.
I verified the cmdlets work in system context locally. A future PR will add running our pester tests using psexe.exe
Microsoft Reviewers: Open in CodeFlow