core icon indicating copy to clipboard operation
core copied to clipboard

Get executing directory of single file exe

Open AhmadChaker opened this issue 7 years ago • 4 comments

Issue Title

I am using .NET Core 3.0, I'm trying to get the executing directory of the single file exe however it looks like this isn't possible easily. Is there an API in the future that can be used to get this ?

This is an issue when the single file exe is called from a directory other than its own. i.e. My command prompt is in C:\ and I am trying to execute test.exe in C:\temp\test.exe

When I use Directory.GetCurrentDirectory() and other related APIs it returns the directory where the single file exe is unzipped i.e. the C:\Users\user\AppData\Local\Temo.net and not the directory where the single file exe is C:\temp\test.exe

AhmadChaker avatar Oct 11 '19 06:10 AhmadChaker

You can use Process.GetCurrentProcess().MainModule.FileName to get the full path to the bundle exe to unblock this scenario but I've previously opened an issue to consider an API change - https://github.com/dotnet/core-setup/issues/7491

dasMulli avatar Oct 11 '19 09:10 dasMulli

Directory.GetCurrentDirectory() not returning the directory you execute from by default seems like a bug. @jeffschwMSFT

scalablecory avatar Oct 14 '19 17:10 scalablecory

We choose to not change the current directory, as in some sense it as not changed - the native entry point is still executing from the currentdirectory, only the extracted components are in a new directory.

cc @swaroop-sridhar

jeffschwMSFT avatar Oct 14 '19 17:10 jeffschwMSFT

This is a dup of https://github.com/dotnet/core-setup/issues/7491 For more details please see the comments in https://github.com/dotnet/core-setup/issues/7491

swaroop-sridhar avatar Oct 14 '19 18:10 swaroop-sridhar