C
C#3y 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
sibber3y ago
replace the extension with exe theyre always in the same folder anyway
Halfbax
HalfbaxOP3y ago
I will do that, but is it clean?
sibber
sibber3y ago
i mean its the only option
Halfbax
HalfbaxOP3y 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 User3y ago
Message Not Public
Sign In & Join Server To View
sibber
sibber3y ago
it covers edge cases not necessarily always
reflectronic
reflectronic3y 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
sibber3y ago
yeah but if you dotnet YourApp.dll it will return the path to the dll actually if you run the exe too
Accord
Accord3y 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.
Want results from more Discord servers?
Add your server