Cannot get original executable path for .net core 3.0 single file '/p:PublishSingleFile=true'

Viewed 2406

I published a .net core console app with '/p:PublishSingleFile=true' option, but now assembly path is the temporary path where it inflated to.

Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)

now returns:

C:\Users\DEFUSER\AppData\Local\Temp\.net\myApp\3dzfa4fp.353\_myApp.json

originally:

C:\devel\myApp\bin\publish\_myApp.json

How can I get the original path of where i put the exe file originally?

thanks in advance!

2 Answers

There is a new .NET 6.0 property Environment.ProcessPath added exactly for that reason

Returns the path of the executable that started the currently executing process

Design notes can be found here

Related