SharePoint Pals
 | Sign In
Windows Application – Prepare an MSI which will update the Config File Values during Installation – Packaging and Deployment Project Type
by Sathish Nadarajan 12 Nov 2015
SharePoint MVP
Today  :   8     Total  :    4351

In one of the recent project requirement, we were creating a Windows Application. That needs to be packed as an MSI and the application requires some configuration values as well. In that case, we cannot ask every user to update their app.config file manually after the installation as this is an Windows Application. In that case, I wanted to create the MSI itself, to be capable to update the config files for us during the installation.

Let us see how to do that step by step. (It’s been a long time, we had gone through step by step right)

1. Create a Windows Application. Here, I have not done any other stuff. On the FormLoad, reading the config value and displays on the form. (For a better understanding, download the source code at the bottom of this article).

2. The solution looks like below.


3. Add a setup project.


4. Now, the solution will be as follows.

5. clip_image006

6. Add an Installer Class on the Windows Application.


7. On the Installer Class, write the following.

     public partial class Installer : System.Configuration.Install.Installer
         public override void Install(IDictionary stateSaver)
             MessageBox.Show(Context.Parameters.Count.ToString(), "Test Count");
             string dataSource = "Data Source =" + Context.Parameters["DataSource"];
             string initialcatalog = "Initial Catalog=" + Context.Parameters["InitialCatalog"];
             dataSource = dataSource + ";" + initialcatalog;
             dataSource = dataSource + ";Integrated Security=SSPI;";
             MessageBox.Show("instance=" + dataSource);
             ExeConfigurationFileMap map = new ExeConfigurationFileMap();
             MessageBox.Show(Assembly.GetExecutingAssembly().Location + ".config");
             //Getting the path location 
             string configFile = string.Concat(Assembly.GetExecutingAssembly().Location, ".config");
             map.ExeConfigFilename = configFile;
             System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(map, System.Configuration.ConfigurationUserLevel.None);
             string connectionsection = config.ConnectionStrings.ConnectionStrings
             ConnectionStringSettings connectionstring = null;
             if (connectionsection != null)
                 MessageBox.Show("removing existing Connection String");
             connectionstring = new ConnectionStringSettings("SqlConnectionString", dataSource);
             config.Save(ConfigurationSaveMode.Modified, true);
         public Installer()

8. Now, we are done with the Windows Application. The rest all steps are on the Setup project.

9. Double click on the Content Files and we will be seeing the three Folders.

a. Application Folder

b. User’s Desktop

c. User’s Program Menu.


10. Add the Output files accordingly. (As these are very basic things, am skipping these)

11. Right click on the Setup Project and select the Custom Actions.


12. On the Install, Select the Primary Output file and view the properties.


13. Edit the CustomActionData with the Value,

/DataSource=[EDITA1] /InitialCatalog=[EDITA2] /UserID=[EDITA3] /Password=[EDITA4]

14. Here the EDITA1, EDITA2 etc., were the TextBox Values on the Interface. Let us see how to add the interface now.

15. Again select the Setup project and click on the Views-User Interfaces.


16. The below screen will be displayed.


17. On the Start, Right click and add dialog.


18. Select a Dialog with 4 Text Boxes.

19. Edit/Verify the Properties of the Dialog Properties.


Make sure that the Property and the Label matches with the string which we framed. These things to be in sync. Otherwise, it may not be updated on the config file appropriately.

20. Now, build the application, we will get the MSI as output. While installing the MSI, it will ask for the config Values.


Download the Source Here

Happy Coding,

Sathish Nadarajan.

blog comments powered by Disqus

SharePoint Pals

SharePoint Pals, a community portal for SharePoint developers, Administrators and End Users. Let's join hands and share the point together.
Read this on mobile


Angular Js Training In Chennai
Advanced Angular Js training with real world developer scenarios
Angular Js, Web Api and Ionic for .Net Developers
All in one client side application development for .Net developers
Angular Js For SharePoint Developers
Get ready for the future. Its no more just C#

Get Connected

SharePoint Resources

SharePoint 2013 and 2010 Web Parts
Free Web Parts with Source Code for SharePoint Community

SharePoint 2013 Books and Tutorials
Collection of free SharePoint 2013 books and tutorials (eBooks, pdfs)

Supported By

Contribute your article and be eligible for a one month Free Subscription for Plural Sight. The Author of the most popular New Article (published in the previous month) will be awarded with a Free One month Plural Sight Subscription. Article can be sent to in a word document.

Related Resources

Recent Tweets

Twitter January 15, 00:25
How To Enable Target Value And Actual Value In #D3 Gauge Chart

Twitter January 15, 00:24
How To Open #SharePoint List Hyperlink Column In Modal #Popup Window

Twitter January 15, 00:24
Quick Introduction To #Asp.NetCore And It’s Features

Twitter January 15, 00:22
How To Configure #PerformancePoint Services To Use Secure Store In #SharePoint 2013

Twitter January 15, 00:21
How To Block Or Disable #Office365 Services

Follow us @SharePointPals
Note: For Customization and Configuration, CheckOutRecent Tweets Documentation