-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Replace ProcessModule.FileName with Environment.ProcessPath and remove PSUtils.GetMainModule #15012
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
| hostname = string.Concat("PowerShell_", processModule.FileName, "_", | ||
| processModule.FileVersionInfo.ProductVersion); | ||
| hostname = string.Concat("PowerShell_", Environment.ProcessPath, "_", | ||
| currentProcess.MainModule.FileVersionInfo.ProductVersion); |
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.
In a further PR I will remove the need to use Process.MainModule.FileVersionInfo here to avoid loading System.Diagnostics.FileVersionInfo.dll assembly on startup on Windows.
src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs
Show resolved
Hide resolved
Co-authored-by: Ilya <darpa@yandex.ru>
TravisEz13
left a comment
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.
I looks okay to me.
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
I see that this PR has been already approved, is anything else needed to get this merged? |
|
We should have approval from one of the code owners either @adityapatwardhan or @daxian-dbw |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
@Fs00 Thank you for your contribution! |
|
You're welcome!👍🏻 |
|
🎉 Handy links: |
PR Summary
This PR replaces all occurrences of
PsUtils.GetMainModule(currentProcess).FileNamewith the newEnvironment.ProcessPathAPI as suggested in #14332 (comment).Furthermore, all the other places in which a ProcessModule needs to be retrieved have been changed to use
Process.MainModule.NET API directly instead of going throughPSUtils.GetMainModule(which has been removed).PR Context
In the comment linked above, @iSazonov reported that calling
PsUtils.GetMainModule(currentProcess).FileNamewas particularly expensive (27ms). The newEnvironment.ProcessPathAPI has been implemented to tackle this problem and there is even an official .NET analyzer to recommend switching to it (dotnet/roslyn-analyzers#4909).While making that change, I noticed that
PSUtils.GetMainModulewrappedProcess.MainModulein a retry loop to workaround a .NET Framework 2.0 (!) BCL issue, therefore it shouldn't be needed at all nowadays.Fixes #13790
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).