Replace ProcessModule.FileName with Environment.ProcessPath and remove PSUtils.GetMainModule#15012
Replace ProcessModule.FileName with Environment.ProcessPath and remove PSUtils.GetMainModule#15012adityapatwardhan merged 3 commits intoPowerShell:masterfrom Fs00:env-processpath
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.
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 <[email protected]>
|
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).