Jasinski Technical Wiki


Home Page
All Pages

Quick Search
Advanced Search »

Contributor Links

Create a new Page
File Management
Your Profile

Other Wiki Sections



Installer Projects - Visual Studio

Modified on Wed, Jun 06, 2012, 11:17 AM by Administrator Categorized as Visual Studio and Developer Tools


This article gives an overview of working with Installer projects within Visual Studio. Refer also to Web.Config Transformations with Web Setup Project - Visual Studio.

Installer projects are primarily declarative in nature, with the exception of Installer Classes, which are included in your application code.

ItemHow to Configure
Files to installView menu > Editor > File System
Files NOT to installSolution Explorer > Installer project > "Content Files" or "Primary output" > right-click > Exclude filter
Registry entriesView menu > Editor > Registry
File Types to createView menu > Editor > File Types
Installer dialogsView menu > Editor > User Interface
Custom actionsView menu > Editor > Custom Actions
Launch conditionsView menu > Editor > Launch Conditions
PrerequisitesSolution Explorer > Installer Project > right-click > Properties > Prerequisites button


Changing a Connection String Based on User Input

1. Include a "Textboxes" dialog in your User Interface.

2. Specify the following property values for the Textboxes dialog.

Edit2Value(default value)
Edit3LabelSQL Server Instance
Edit3Value(default value; e.g., ".\SQLEXPRESS")

3. Add a Custom Action on "Primary Output...", and in its CustomActionData property, specify "/Site=[TARGETSITE] /Vdir=[TARGETVDIR] /SqlSvr=[SQLSERVERINSTANCE]". (This will refer to the value in the textboxes from the previous step.)

4. To your application code, add an installer class. Within its override of the the Install method, add the following code.

Dim site As String = Me.Context.Parameters.Item("site")
Dim appName As String = Me.Context.Parameters.Item("vdir")
Dim sqlServerInstance As String = Me.Context.Parameters.Item("sqlsvr")

Dim siteNum as Integer = Integer.Parse(site.Substring(site.LastIndexOf("/") + 1)) - 1
Dim mySite As Microsoft.Web.Administration.Site = mgr.Sites(siteNum)
Dim myApp As Microsoft.Web.Administration.Application = mySite.Applications("/" & appName)
Dim mgr As ServerManager = New ServerManager()
Dim rootPath As String = myApp.VirtualDirectories("/").PhysicalPath
TweakConnectionStringDataSource(rootPath, "Local", sqlServerInstance)

5. Add the following method to your installer class.

Private Shared Sub TweakConnectionStringDataSource(rootPath As String, connectionStringName As String, newDataSource As String)

    Dim configFile As String = Path.Combine(rootPath, "web.config")
    Dim doc As XmlDocument = New XmlDocument()
    Dim xPath As String = "/configuration/connectionStrings/add[@name='" & connectionStringName & "']"
    Dim node As XmlNode = doc.SelectSingleNode(xPath)
    Dim attr As XmlAttribute = node.Attributes("connectionString")
    Dim conn = New SqlConnectionStringBuilder(attr.Value)

    ' We do this tweak because, for some reason, when the user specified ".\SQLEXPRESS" (for example)
    ' it comes in here as ".\\SQLEXPRESS".
    newDataSource = newDataSource.Replace("\\", "\")

    conn.DataSource = newDataSource

    attr.Value = conn.ConnectionString
    Dim newConfigFile = configFile ' Path.Combine(rootPath, "web2.config") ' This is for testing

End Sub

ScrewTurn Wiki version Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2023, Patrick Jasinski.