-
Notifications
You must be signed in to change notification settings - Fork 1k
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
fix: Application.ExecutablePath
returns dll instead of exe (#2801)
#2838
Conversation
Codecov Report
@@ Coverage Diff @@
## release/3.1 #2838 +/- ##
====================================================
+ Coverage 24.85382% 24.8638% +0.00997%
====================================================
Files 844 844
Lines 260290 260274 -16
Branches 36896 36894 -2
====================================================
+ Hits 64692 64714 +22
+ Misses 190874 190837 -37
+ Partials 4724 4723 -1
|
…2801) In .NET artifacts are DLLs even for executable projects. With some automagic they get bundled into executables. However `Assembly.GetEntryAssembly()` always returns the dll instead of the exe. Following the guidance from the Runtime team retrieve the path to the executable via `GetModuleFileNameW` call. Resolves dotnet#1143 (cherry picked from commit 2af3af9)
a17e689
to
abd221b
Compare
} | ||
} | ||
StringBuilder sb = UnsafeNativeMethods.GetModuleFileNameLongPath(NativeMethods.NullHandleRef); | ||
executablePath = Path.GetFullPath(sb.ToString()); |
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 this does return a relative path at any point, GetFullPath is going to resolve it by whatever the current directory is, which may or may not be the application directory:
C:\>cd NotApplicationDir
C:\NotApplicationDir> C:\MyApp\App.exe
If GetModuleFileNameLongPath
actually returns a relative path at any point, this will return C:\NotApplicationDir\App.exe
.
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.
From my reading, it probably doesn't, and you are doing this just to normalize the path, right?
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.
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.
From my reading, it probably doesn't, and you are doing this just to normalize the path, right?
I believe so too. That's how the original code had it. It may be redundant but I'm not going to change it on a service branch. :)
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.
doc says
Retrieves the fully qualified path
which rules out relative paths (actually I commented on this on the other PR)
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
This is good for 5.0, but until we find out that it's blocking servicing, I think that this won't meet a servicing bar for 3.1. |
Resolves #1143
For discussions and tests refer to #2801
(cherry picked from commit 2af3af9)
Proposed changes
In .NET artifacts are DLLs even for executable projects. With some automagic they get bundled into executables.
However
Assembly.GetEntryAssembly()
always returns the dll instead of the exe.Following the guidance from the Runtime team retrieve the path to the executable via
GetModuleFileNameW
call.Customer Impact
Regression?
Risk
Test methodology
Application.ExecutablePath
returns dll instead of exe #2801Microsoft Reviewers: Open in CodeFlow