How to add registry value containing executable path in visual studio deployment project at installation

Go To StackoverFlow.com

1

I know that [TARGETDIR] will get me the installation Directory, but I also want the name of the executable. I think it should be something like [TARGETDIR][OUTPUTPATH] or maybe just [OUTPUTPATH], but I can't find anything on a installer property that contains the name of the executable that I'm installing.

I need this information to put in the registry at install-time. I know I can do it with a custom action from my project, but I'd rather just use the installer properties if I can.

2012-04-05 19:50
by jww
Don't you know the name of executable you are installing? Here is the list of all the properties and it does not look like it has what you wan - Anurag Ranjhan 2012-04-05 20:05
Yes I know the name, but I do not want to hard-code that value in-case somebody comes along at a later date and changes it - jww 2012-04-05 20:18


0

I think [AssemblyPath] might work
(don't have it in front me to test, if I recall right)

2012-04-05 20:37
by NSGaga
[AssemblyPath] returns an empty string - jww 2012-04-05 22:02
yes that seems to work from the Installer in C# - you need this from the (setup project) Registry area I'm guessing. I think your best option then is to add a custom action and map to an installer class in your app or lib - which will be called on actions from setup project. There you can have your app name (by calling Assembly.GetExecutable... etc.) and add the registry from there. Let me know if you need more info on that - and I'll rephrase my answer to include/remove - NSGaga 2012-04-05 22:33
What I ended up doing was

1) passing [TARGETDIR] to a custom action as described at http://msdn.microsoft.com/en-us/library/9cdb5eda%28v=vs.100%29.aspx

2) using basic System.IO to search that directory for "*.exe" files in the OnAfterInstall method of the custom action. In my case, there is only 1 .exe file so I can be certain that is the application I just installed. (I can then add that path to the registry or do whatever I want - jww 2012-04-05 23:56

Something like that yes - you can simply use Context.Parameters["TargetDir"] no need to pass anything (I guess you did just that). And if you're calling it from the same 'exe' (i.e. your Installer class is there) then you can use Assembly.GetExecutingAssembly().Location to get the current exe - and just trim, use Path. to get the name of the file - then add to target dir (here, I'm not sure if its' loaded at the 'target' or I'm thinking not). Then check for, whether that exists (basically you could do that on Install not AfterInstall as you know it'll be there) - NSGaga 2012-04-06 00:08
That'd be 'safer' still, as you don't have to trust having just one .exe. - and you 'know' executing assembly is the real/final deal - NSGaga 2012-04-06 00:12
Ads