C
C#2y ago
Halfbax

❔ Getting exe path of entry point

I do have a WinUI 3 project and I am unable to retrieve the exe path of my application. That's what I have tried. But I get the dll only.
string? target = Assembly.GetAssembly(typeof(App))?.GetName().CodeBase;
// returns the dll path instead of the exe
string? target = Assembly.GetAssembly(typeof(App))?.GetName().CodeBase;
// returns the dll path instead of the exe
11 Replies
sibber
sibber2y ago
replace the extension with exe theyre always in the same folder anyway
Halfbax
Halfbax2y ago
I will do that, but is it clean?
sibber
sibber2y ago
i mean its the only option
Halfbax
Halfbax2y ago
I think I have found the optimal solution Environment.GetCommandLineArgs() returns the file name Thanks for the help. 🙂 Nice to know that Path has a method for changing the extension. Why did they do that? Isn't it just a wrapper for String.Replace?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
sibber
sibber2y ago
it covers edge cases not necessarily always
reflectronic
reflectronic2y ago
Environment.ProcessPath Property (System)
Returns the path of the executable that started the currently executing process. Returns null when the path is not available.
sibber
sibber2y ago
yeah but if you dotnet YourApp.dll it will return the path to the dll actually if you run the exe too
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.