With Microsoft .NET, configuration for any .NET application is
stored in XML files, as compared to the Registry which is used
for normal Windows applications. With the
"Microsoft .NET Configuration" tool
(Administrator Tools -> Microsoft .NET Configuration) that
comes with the .NET Framework, it is possible to configure
some application properties. But there is no tool available
to manage application settings of a .NET application.
Each time a .NET application is installed on a new machine,
the system administrator has to edit the XML file in notepad
or a similar editor and make the required changes. With many
.NET applications installed on production machines, it is
a real maintenance issue for the Operations team, to find
these configuration files and edit them. Another point to
remember is that the Operations team might not have the same
skills as the developer, in terms of familiarity with XML
files or determining the name and location of the appropriate
configuration file for a specific application.
Need for application configuration editor and automation
Most big/medium size organizations need a single tool to manage
application settings of .NET applications (Both Windows Forms
and ASP.NET applications). Also all ASP.NET or Windows Forms
based applications should support 'Windows Installer' kind of
setup programs and should invoke configuration editor tool,
so that person who is installing the application can enter
correct configuration information while installing it.
In this article I will focus on the developing configuration editor tool and building windows installer package, to support .NET application maintenance. You can download the sample code and the tools used in this article, with complete source code, from download link. You are free to modify the source and use it as per your needs.
Focus of this article is on, installing and configuring a .NET application in production environment. We will look at ways, how to simplify Operation team's work in installing and maintaining the .NET application. We will look at an ASP.NET application (developed and tested) ready to be deployed to production environment. Solution described in this article is not limited to ASP.NET application and can be used for Windows Form based .NET Application or Web services application.
Seth Financials, a big financial organization, has a lot of .NET development. Development includes ASP.NET applications, Web services and Windows Forms based applications.
One of these applications is: Prakash Book Store, an ASP.NET application that uses following application settings from configuration file to name few: Connection String, Log level, Log directory, Admin email ID
For obvious reasons Operations team does not like to give production configuration details, up-front to development team and they want to enter it, while installing the application. Operations team does not like to fiddle around with XML configuration files and they want simple user interface to change any configuration. Also Operations team is looking for configuration editor tool that can be used for changing configuration of .NET applications at later time also.
Following are the requirements for installing and configuring .NET applications:
Requirement 1: Require Configuration Editor tool, to manage different .NET application settings. Installer programs that install any .NET application should invoke the tool. Tool can also be used to manage existing .NET application configuration.
Requirement 2: Provide Windows Installer packages for all applications. Invoke above tool after installation of any .NET application so that operations team can change configuration settings.
Requirement 3: Tools that are invoked during installation process should run under secure configuration. ASP.NET application installations should install the tool in /bin directory of the application virtual directory, so that it is not accessible to web users.
Requirement 1: (ConfigEditor)
Since configuration for any .NET application is stored in XML configuration file it is very easy to build Windows Forms based application and use System.Xml namespace classes to manipulate configuration files. This will address Requirement 1. ConfigEditor should read command line arguments passed, to switch to safe operation mode when invoked from an installer.
Setup project templates that come with Visual studio .NET are very easy to use, for creating windows installer setup packages. There is a lot of flexibility in the setup projects: to add new user input dialogs or change look and feel (bitmap/icon/text) of setup screens or add custom actions. To invoke configuration editor, after the installation is completed, we can use 'Custom Action' feature in the setup project.
Requirement 3: (Custom Actions in setup with arguments)
In the setup project created, ConfigEditor tool should be added to bin directory. [TARGETDIR] property in the setup project can be used to figure out installation directory. This and additional properties should be passed to ConfigEditor tool, as arguments. This will allow ConfigEditor to recognize that it is invoked from installer and behave differently vs. normal invocation.
Requirement 1: Following are high level details in creating ConfigEditor tool
Select "Windows Forms Application" project in Visual Studio .NET
For select any configuration file use "OpenFileDialog" control
Use System.Xml.XmlDocument to read and write XML configuration files
Use DataSet and DataGrid control for presenting configuration details
Fig. 1: Configuration Editor tool
Requirement 2: Following are high level details in creating Setup package
For ASP.NET or web services applications use "Web Setup project" template and for "Windows Forms Applications" use "Setup project" template in Visual studio .NET
Use View->Editor menu to add the file to file system that are required on target machine (You can simply select Project Output and Select "Content files" or "Primary Output" ).
Use View->Custom actions to invoke any tool that needs to be invoked after running and installing setup. (Make sure to change "InstallerClass = False" for tool in Custom Actions)
In Custom Actions -> Install-> select the tool output added and check properties
In properties add "[TARGETDIR] Installer" in the arguments. This will allow use to pass these arguments to the tool when it is invoked form Installer.
Fig. 2: Custom Action properties
Sample Code and source
Attached sample code has all the source code with the tools you need.
You can download a zip file (311 kb) containing the code from here.