Using a Post-Build Script to set the InstallLocation property in VS Setup Projects
If you check the registry for (un-)installation information about installed applications, you can notice that the InstallLocation registry key is mostly empty. This is because most installers do not set ARPINSTALLLOCATION property to the value of [TARGETDIR] during installation. Unfortunately, this also includes Visual Studio setup projects:
What we can do so solve this problem is inserting a simple Type 51 Custom Action into the installer. What I was looking for, was an easy solution to automate this tasks (rather than editing them with ORCA or any other tool), and I eventually came up with a post-build event that updates the MSI database directly. Fortunately, I had a similar script in place from an earlier setup, so adjusting it was quite easy 🙂
In the link below, you can find a VBS script (SetArpInstallLocation.vbs) that inserts the required custom action for you and makes sure the ARPINSTALLLOCATION property is set during installation. All you have to do is calling the script during the post-build event of your setup project.
In the sample below, the script file has been placed in the same folder as the installation project. Accordingly, the build action looks like this:
"$(ProjectDir)SetArpInstallLocation.vbs" "$(BuiltOuputPath)"
If the installer file is re-built with this script in place, the installer writes the InstallLocation properly to the registry during installation 😀
Download VBS script file: SetArpInstallLocation.vbs
Thanks for the useful and clear instructions. I didn’t fancy trying to work out what “Orca” is (it seems to frequently crop up in discussion around MSI packages). I just use Visual Studio 2008 and expected the basics like installation locations to be handled out of the box without having to learn a new application so this is a really helpful little script.
Absolutely excellent. Thanks for publishing the script. Can’t think why Microsoft would leave out the install location setting from the registry when all the other application’s settings are written there during an installation? Bug? Oversight? or just plain bloody-mindedness!
Thanks a lot for this script and all the instructions.
This has saved my project 😉
You’re very welcome – glad the script was helpful 🙂
Thanks for posting this. Saves me from updating through Orca after every build
thanks for posting this, but I’m a little confused as to why this would work though other than on the development machine. Isn’t the PostBuildEvent for when Visual Studio has finished building the project? And that has been my experience with it. The script is only called during the build process – not when the installation is actually run.
Can anyone clarify?
Thinking further on this, perhaps an option is to execute the script as a custom action in the commit phase of the install. I’m unsure how you would pass the script the install location, but the script can obtain that for itself so not need to be passed anything.
Thanks mate!
Niiiice – I searched all over for a solution to this situation, and finally found it here. Dropped this script in and it worked great. Thx!
Brilliant! I have expanded your script to also update the DefBannerBitmap and it works a treat!
Glad it works for you! If you think it’s worth sharing your changes, feel free to post them here 🙂
Very useful scripts. Save me a lots of time!