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  :   4     Total  :    3609

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 October 21, 21:34
How to Add a JS Link Reference to the Display Form or Any other ASPX Programmatically using CSOM PNP in SharePoint -

Twitter October 20, 13:01
How to Add a JS Link Reference to the NewForm and EditForm Programmatically using CSOM PNP in SharePoint Office 365-

Twitter October 12, 12:15
How to Deploy Provider Hosted Apps (Add-Ins) by App Stapling in SharePoint Office 365 -

Twitter October 11, 13:39
How to Deploy Provider HostedApp programmatically using CSOM in SharePoint Office 365 Activating Developer Feature -

Twitter October 10, 09:26
How to Use Angular HTTP Services in SharePoint List -

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