PostBuildEvent for Visio Solution Publishing

If you are like most people you probably hate repetitive tasks. Adding the necessary changes to your MSI for PublishComponents support using the Visio Solution Publishing tool is one of these tasks. Not only that, if you deploy your MSI to a Vista machine you will also need to tweak the Custom Action that is added to your MSI by the Visio Solution Publishing tool as described in this article.

So why not automate this so all you have to worry about is clicking the Build or Rebuild buttons on your Setup project.

Create a configuration file for the Visio Solution Publishing tool

If you are not familiar with the Visio Solution Publishing tool then please read this article.

Once you finish editing all the entries for the Visio content contained in your MSI file you can click the Save button and save a copy of this configuration (*.vpc) that we will later use as a command line parameter to vissolpublish.exe from within a batch file.

image

Create a script to make the fix for Vista UAC support

The Visio Solution Publishing tool adds a script to your MSI that helps Visio refresh its cache the next time it is run. The type that is set for this action is not compatible with Vista if UAC is enabled (which is the default setting).

Create a new text file with the .VBS extension and copy this to the content of that file:

Const msiOpenDatabaseModeTransact = 1

Dim msiPath

msiPath = WScript.Arguments(0) 'MSI file from the command line

Dim installer

Set installer = CreateObject("WindowsInstaller.Installer")

Dim openMode

openMode = msiOpenDatabaseModeTransact

Dim database

Set database = installer.OpenDatabase(msiPath, openMode)

Dim view

Set view = database.OpenView("UPDATE CustomAction SET CustomAction.Type = '3622' WHERE CustomAction.Action = 'VisSolPublish_BumpVisioChangeId'")

view.Execute

database.Commit

Set view = Nothing

Set database = Nothing

This script will change the Type to ‘3622’ which allows for elevated privileges when installing to Vista. Without this change you will get an install error at the very end of your installation as described in this article.

Create a batch file to apply the configuration and run the script

Now that you have the configuration file (*.vpc) and the script (*.vbs) to patch the MSI you need a single batch file that you can easily reference on the PostBuildEvent property of your Setup project in Visual Studio.

Create a new text file with the .BAT extension and copy this to the content of the file:

cd /d %~dp0

"C:\Users\chhopkin\Documents\My Dev Stuff\Tools\Visio 2007 SDK Tools\VisSolPublish.exe" /apply SimpleVSTO3Sample.vpc %1

cscript vissolpublish_vista_fix.vbs %1

Setup the PostBuildEvent property

Before setting the PostBuildEvent property you should find a location to store the configuration file, the script file and the batch file. I put my files in the same folder as the setup project file (*.vdproj).

image

This location makes it easy to build the PostBuildEvent as follows:

"$(ProjectDir)vissolpublish_and_vista_fix.bat" "$(BuiltOuputPath)"

image

$(ProjectDir) and $(BuildOutputPath) are both built in macros that make it easy to reference the path and filename of your MSI

Conclusion

At this point you should now be able to simply set your configuration to ‘Release’, run a new build, and then run the MSI on your test machines without forgetting to make any additional changes to your MSI.