Thoughts about setup and deployment issues, WiX, XNA, the .NET Framework and Visual Studio
All postings are provided AS IS
with no warranties, and confer no rights. Additionally, views expressed
herein are my own and not those of my employer, Microsoft.
I am using the Visual Studio setup/deployment project to create an MSI to install my application. I would like to add some functionality to this MSI that does not appear to be supported in the Visual Studio IDE (such as modifying the default install path based on a registry value on the system). I know how to do this by directly editing the MSI, but I don't want to have to manually edit the MSI each time I build. Are there any other options I can use in this scenario?
There is a limited set of customizations you can make to an MSI in the Visual Studio IDE UI for a setup/deployment project. By limited, I mean that there are a lot of features that are natively supported in Windows Installer MSI format that are not exposed for customization in the Visual Studio IDE. Examples include changing the default install path based on a registry value, advanced setup UI features such as updated banner text or a "launch my product" checkbox on the final screen, creating custom actions that reference external executable files, or setting various custom action attributes (among other things).
If you would like to automate the ability to customize an MSI that is built by the Visual Studio setup/deployment project in a way that is not currently supported by the UI in the Visual Studio IDE, you can write a script that accesses the Windows Installer object model to perform these customizations. Then you can create a post-build step in your Visual Studio setup/deployment project to run your script after the MSI has been built so that the final result each time you build will be an MSI package with your additional customizations made to it.
As an example, you can use the sample script at this location to add a checkbox to your MSI's setup UI that will let the user choose whether or not to launch your product after setup finishes.
If you would like to include this script as a post-build step in a Visual Studio setup/deployment project, you can use the following steps:
Note that the quotation marks in the command line in step 8 are very important because the script will not work correctly without them. Make sure to double-check that you have put quotes in the proper places.
<update date="8/23/2006"> Updated the steps needed to configure post-build commands in the Visual Studio UI because they are different for setup projects than for other Visual Studio project types </update>
<update date="5/31/2007"> Updated steps to mention the need to rename WindowsApplication1.exe to the name of the EXE in each project that you want to launch. Also fixed a typo in the variable BuiltOuputPath. </update>
<update date="8/26/2008"> Updated steps to be more specific about what folder to save EnableLaunchApplication.js to </update>
<update date="3/15/2009"> Fixed broken link to the sample script </update>
<update date="7/26/2012"> Fixed bad HTML formatting and misnumbered steps </update>
<update date="2/8/2016"> Fixed broken link to Windows Installer object model documentation </update>
First off, an apology for the lack of posts. As you may recall from last time, Mike Sampson has left
Question: I have built an installer using the Visual Studio 2005 setup project wizard. It installs correctly
Im getting an error coping in the exact cscript command. Any Idea's?
cscript.exe "$(ProjectDir)EnableLaunchApplication.js" "$(BuiltOutputPath)"
The error is Error 1 'PostBuildEvent' failed with error code '1' 'Unspecified error' C:\Documents and Settings\jerry\My Documents\Visual Studio 2005\Projects\svcAdminLanMonitor\AdminLanMonitorSetup\AdminLanMonitorSetup.vdproj AdminLanMonitorSetup
Hi Boomport - Can you double check that you copied the EnableLaunchApplication.js file into the project directory for the project that you are trying to build? You may have copied it to a different folder location. Hopefully this helps. If that doesn't help, I suggest posting a question on the MSDN Forums at http://forums.microsoft.com and hopefully someone there can suggest another possible workaround.
As a special treat to all of you, we are going to mostly step away from the signing example for a little
I'm getting this same error:
The error is Error 1 'PostBuildEvent' failed with error code '1' 'Unspecified error'
I put the .js file in the same folder as my project file and even in the folder above, just to eliminate all issues. My setup project is VERY simple (for testing only). It has one EXE and nothing else (no custom actions, etc.).
If I remove the PostBuildEvent, the project compiles fine. However, it will not build with the following text:
I've dug around on the forums link you posted but I see no solution there to this problem.
Any other ideas? Any chance you could post a simple project with this working? Perhaps something strange about my system's configuration (though my system is pretty standard - VS2005, XP, etc.).
Hi JohnMAndre - I'm sorry for the hassles here. There were a few small problems causing these steps to not work.
First, I incorrectly spelled the variable BuiltOuputPath (the wrong spelling of ouput is actually right, but I fixed it when I wrote the blog and VS doesn't recognize the variable BuiltOutputPath). I did the same thing in my blog post at http://blogs.msdn.com/astebner/archive/2007/01/22/updated-steps-for-setting-the-noimpersonate-flag-for-a-custom-action-in-visual-studio-2005.aspx.
Second, the .js file inside of the zip file on my file server (http://astebner.sts.winisp.net/Tools/EnableLaunchApplication.zip) was named EnableLaunchApplication js (without a . before js). If you extracted the file but didn't rename it, VS won't be able to find it to run it.
Third, there is a modification you have to make to the contents of the .js file for it to run correctly. You have to provide the name of the application that you want to be launched at the end of installation. It is hard-coded to WindowsApplication1.exe in the .js file currently. You'll need to change that to meet your needs before rebuilding your MSI.
After all of the above fixes, I was able to get this example to work for a simple setup project. Hopefully it will work for you as well. If it works, you will see dialogs indicating the steps it is taking. You can remove the dialogs after you make sure it is working so it won't interrupt your build process.
I have updated the zip file to correctly name the file EnableLaunchApplication.js inside the zip file, and I will also update the text of this blog post with the correctly named variable BuiltOuputPath.
Please let me know if you have any further issues.
Yeah! I got it to work.
Unfortunately, I cannot get "$(BuiltOutputPath)" to work - I have to pass in the literal path of the msi file. Not ideal but it works.
I tried several versions around this but nothing worked. It just passes in an empty string.
Still, thanks for this. I'm glad I have a solution.
One more question related to this.
Do you have any idea how I could launch the installed application without prompting the user with a checkbox? That is, I don't want to give them a choice, I simply want to launch it after the installation is complete.