-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Not possible to get the executable path for self-contained executable #13051
Comments
@sirjeppe you are correct. As we built this first wave of this feature we have not provided the convenience APIs that return all the paths involved in the process. Right now there are people taking advantage of the CodeBase path to determine if they are running single-exe or not. We are open to feedback about what APIs would be nice on determining the location of files. In the meantime could you use current working directory? |
You can use |
For the records:
I guess this can be closed then? |
@Symbai for now it can. We have it on our roadmap to potentially offer convenience APIs to provide this sort of information. We are gathering data on what makes the most sense. |
For the record: I work for Microsoft, but have no work account for GitHub so I'm using my private one. @jeffschwMSFT - The current page (https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.getentryassembly?view=netframework-4.8) for at least the Assembly.GetEntryAssembly() method says: "Gets the process executable in the default application domain. In other application domains, this is the first executable that was executed by ExecuteAssembly(String)." - i.e. that it should return the executable (not the temporarily extracted modules which seems to be the case currently, if I have interpreted the docs correctly, of course). IMO this is misleading in the case I have reported here, so I would love to see an update to the documentation as the outcome of this ticket before it is closed that explains/provides the workaround by @Symbai and/or some other text to inform users about this behavior mismatch between self-contained executables and regular executables. Preferrably with a complete solution to get the expected path as mentioned in e.g. many Stack Overflow posts and the official documentation etc. |
@sirjeppe docs have a separate tracking mechanism for feedback. I would encourage this issue to be about the need for better API access and we can file a specific issue to update the wording. Make sense? |
Absolutely! Do you mean this ticket will stay open until such APIs are in place or are you still agreeing that this issue will be closed and that a new ticket will be opened on the documentation clarification? |
We may keep this one open for tracking the need for better API. The doc feedback is better suited here: https://github.com/dotnet/docs |
Ok! I will report a second ticket there then. Thank you! |
@sirjeppe even better you could consider offering a PR in the docs repo... |
|
That can be set by parent process though, so not the same thing as path to executable. |
@Symbai |
@kamronbatman, you can use |
This issue is a dup of https://github.com/dotnet/core-setup/issues/7491 |
Is there still no convenient way to do this as of .NET Core 3.0 stable? |
This works for me. |
@fatihyildizhan Process current directory isn't the same as application directory, it'll only be the same when program launched from same folder it's in. But it can be changed both in process and from launching process. |
@fatihyildizhan this would not work for you if you use self-contained executable, a .NET Core 3.0+ feature. Just an example. |
try this Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) |
@Symbai |
@mlockett42 See the above answer from jkotas #13051 (comment) |
When calling Assembly.Get*Assembly().CodeBase for a self-contained .NET Core 3 project, it reports a temporary directory rather than the folder where the executable actually is located.
Put the code above in a project with these settings:
Then publish the app to e.g. C:\AssemblyReflectionIssue and launch it. Something like this will be printed:
C:\Users\user\AppData\Local\Temp.net\AssemblyReflectionIssue\2bn5yvkd.pjb\AssemblyReflection.dll
file:///C:/Users/user/AppData/Local/Temp/.net/AssemblyReflectionIssue/2bn5yvkd.pjb/AssemblyReflection.dll
file:///C:/Users/user/AppData/Local/Temp/.net/AssemblyReflectionIssue/2bn5yvkd.pjb/AssemblyReflection.dll
file:///C:/Users/user/AppData/Local/Temp/.net/AssemblyReflectionIssue/2bn5yvkd.pjb/AssemblyReflection.dll
I would expect at least one of the calls to return the actual path (C:\AssemblyReflectionIssue)?
The text was updated successfully, but these errors were encountered: