Home > .NET, Deployment > Using a Post-Build Script to set the InstallLocation property in VS Setup Projects

Using a Post-Build Script to set the InstallLocation property in VS Setup Projects

December 14th, 2008

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:

image

 

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)"

 

image

 

If the installer file is re-built with this script in place,  the installer writes the InstallLocation properly to the registry during installation 😀

image

 

Download VBS script file: SetArpInstallLocation.vbs


Author: Categories: .NET, Deployment Tags: ,
  1. January 28th, 2009 at 23:35 | #1

    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.

  2. Richard
    December 1st, 2009 at 20:57 | #2

    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!

  3. GuiGau
    January 11th, 2010 at 09:46 | #3

    Thanks a lot for this script and all the instructions.
    This has saved my project 😉

  4. January 11th, 2010 at 09:49 | #4

    You’re very welcome – glad the script was helpful 🙂

  5. Max
    January 12th, 2010 at 01:41 | #5

    Thanks for posting this. Saves me from updating through Orca after every build

  6. Matt
    June 7th, 2011 at 16:39 | #6

    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?

  7. Matt
    June 7th, 2011 at 17:21 | #7

    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.

  8. Spyros
    October 19th, 2012 at 14:28 | #8

    Thanks mate!

  9. Chris
    October 20th, 2014 at 23:38 | #9

    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!

  10. December 20th, 2014 at 08:18 | #10

    Brilliant! I have expanded your script to also update the DefBannerBitmap and it works a treat!

    • December 20th, 2014 at 09:45 | #11

      Glad it works for you! If you think it’s worth sharing your changes, feel free to post them here 🙂

  11. Kevin
    May 25th, 2016 at 15:13 | #12

    Very useful scripts. Save me a lots of time!

  1. January 29th, 2009 at 08:57 | #1
  2. August 29th, 2013 at 14:41 | #2