-
Notifications
You must be signed in to change notification settings - Fork 234
Make initial logging work in constrained language mode #1222
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
Conversation
private static object GetPSVersion() | ||
{ | ||
#if CoreCLR | ||
return typeof(PSObject).Assembly | ||
.GetType("System.Management.Automation.PSVersionInfo") | ||
.GetMethod("get_PSVersion", BindingFlags.Static | BindingFlags.Public) | ||
.Invoke(null, Array.Empty<object>()); | ||
#else | ||
return typeof(PSObject).Assembly | ||
.GetType("System.Management.Automation.PSVersionInfo", BindingFlags.Instance | BindingFlags.NonPublic) | ||
.GetMethod("get_PSVersion", BindingFlags.Static | BindingFlags.NonPublic) | ||
.Invoke(null, Array.Empty<object>()); | ||
#endif | ||
} |
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.
isn't this in the VersionUtils
class already?
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.
If it is, we can't use it unfortunately, since we can't load PSES.dll at this stage.
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.
What about using this?
pwsh.Runspace.SessionStateProxy.PSVariable.Get(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.
Could try that!
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.
So, the language mode check works, but the GetVariable
API doesn't because it throws on concurrent access. At that point we'd need to spin up a new runspace to use it, which wouldn't be good for startup. But I simplified the reflection a bit at least
@@ -339,16 +341,17 @@ private string GetPSOutputEncoding() | |||
|
|||
private void LogPowerShellDetails() | |||
{ | |||
PSLanguageMode languageMode; | |||
using (var pwsh = SMA.PowerShell.Create(SMA.RunspaceMode.CurrentRunspace)) |
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.
Curious if this is the same as [runspace]::DefaultRunspace
... probably, right? Since you're getting the LanguageMode.
|
||
private static object GetPSVersion() | ||
{ | ||
using (var pwsh = SMA.PowerShell.Create()) |
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.
Curious if this is the same as [runspace]::DefaultRunspace
... probably, right? Since you're getting PSVersionTable.
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.
LGTM 1 nit
@@ -11,6 +11,9 @@ | |||
using System.Runtime.InteropServices; | |||
|
|||
using SMA = System.Management.Automation; |
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.
Still need this?
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.
Needed for the $outputencoding log
No description provided.