clowd / Clowd.Squirrel

Quick and easy installer and automatic updates for cross-platform dotnet applications
426 stars 39 forks source link

Another Question #124

Closed cupper1 closed 2 years ago

cupper1 commented 2 years ago

Hi, I have another question / Concern... When my app starts it needs another dependency that even the "self-contained" does not handle. That is fine, I include a small installer for it, but when I have tried the application.startuppath + \install\mysetup.exe" it doesn't work.

So I went looking and the installer has created a app.exe in the main folder, and then a version subfolder \myapp-1.2.0. It is this subfolder that includes the \install\mysetup.exe. How in code can I reference this specific place?

Thanks!

remco1271 commented 2 years ago

You can use GetExecutingAssembly() to get the location of your program in the \myapp-1.2.0

System.Reflection.Assembly.GetExecutingAssembly().Location
output: "C:\Users\<USER>\AppData\Local\<AppName>\app-2.1.4\application.exe"

To get the folder "C:\Users\\AppData\Local\" where the update.exe is you can use the UpdateManager() for that. This is what I do in my application:

mgr.CreateShortcutForThisExe(ShortcutLocation.StartMenu | ShortcutLocation.Desktop);
RegisterFileTypes(mgr.AppDirectory);
caesay commented 2 years ago

If you want to find the root (where your app is installed) then UpdateManager.AppDirectory is the correct one.

If you want to know where your exe is currently executing, there is a helper built right into Squirrel for this: SquirrelRuntimeInfo.EntryExePath. Since Assembly.Location returns null when PublishSingleFile is true, it's now better to use Process.GetCurrentProcess() to find the file path of your executing binary.