Replace ProcessModule.FileName with Environment.ProcessPath and remove PSUtils.GetMainModule - #15012
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.
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.
Co-authored-by: Ilya <darpa@yandex.ru>
Travis Plunk (TravisEz13)
left a comment
There was a problem hiding this comment.
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 Aditya Patwardhan (@adityapatwardhan) or Dongbo Wang (@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. |
|
Francesco Saltori (@Fs00) Thank you for your contribution! |
|
You're welcome!👍🏻 |
|
🎉 Handy links: |
…emove `PSUtils.GetMainModule` (PowerShell#15012)
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, Ilya (@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).