How to determine setup version from within an ASP.NET page

I read on Stackoverflow that somebody needed the possibility to determine the MSI installer product version used when installing the ASP.NET application. My suggestion is to store the current MSI product version in the web.config file, and later read that from within the web application.

Here are the steps to do this.

Start Visual Studio 2008 and select File->New project.


Select the ASP.NET Web Application template and choose a new for your project. Click Ok.

Open the web.config file and add the following lines within the <appSettings> element:

Add a simple Label control in the Default.aspx file to show the version infomation.

Add code in the Page_Load event to update the Label with the information from the web.config file.

Add an Install Class to the project by right-clicking on the project in the Solution Explorer and select Add->New Item


Select the Installer Class  and choose a name. Click Add.

Right-click the InstallerHelper.cs file in the Solution Explorer and select  View Code. Add the following code:

Right-click the solution in Solution Explorer and select Add->New Project


From the Project Type, select Other Project Types->Setup and Deployment and choose the Setup Wizard template. Enter a name for the Setup Project and click Ok.

image Click Next.

image Select Create a Setup for a web application and click Next.

image Select Content Files and Primary Output files. Click Finish



Click on the Web Application Folder and edit the Virtual Directory to set the name of your Web application. Right-click the Setup Project and select View->Custom Actions.


Right-click the Custom Actions node and select Add Custom Action.

image Select the Web Application Folder and select Primary Output. Click Ok. 

Click on the Primary output from CheckProdVersion (Active) node and edit the property CustomActionData to contain this line:

/TargetDir="[TARGETDIR]\" /ProductVersion="[ProductVersion]"


Build the solution. Right click on the Setup project and select Build.

Right-click on the Setup project and select Install. Follow the installation wizard and browse to your web application: http://localhost/CheckProdVersion


When you are updating the product version in the setup project, you will get this question:

image Click Yes.

Set the Setup Project property RemovePreviousVersions to True, rebuild the Setup and re-install to verify that the version can be updated.