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!
Based on https://github.com/dotnet/coreclr/issues/25623, which was also confirmed by Scott Hanselman a year later:
Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName)
AppContext.BaseDirectory
.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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With