|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionIn developing ConfigManager.Net, I set out to address the following problems:
ConfigManager.Net solves these problems by executing embedded instructions in the app.config. These instructions are stored in the file as XML comments, and executed in place. AlternativesOther projects have also sought to address the problem of merging configuration files, including XmlConfigMerge. The most common methods of allowing for different settings among team members are: Check-in the settings most appropriate for most team membersDevelopers who need to use different settings must then use a writable copy of the file. The main drawback of this approach is the difficulty of keeping the files in sync. Additionally, every time developers with the writable file gets the latest set of files from the source control, they will be prompted each time to replace the file. Using the external file features of the app.config\web.config fileThe <!-- Reference appSetting in the file localAppSettings.config -->
<appSettings file="localAppSettings.config" />
<!-- Reference appSetting in the file localConnectionStrings.config -->
<connectionStrings configSource="localConnectionStrings.config" />
This approach results in more configuration files that need to be managed and synchronized. It is also limited to the above mentioned sections of the app.config, sections like Using ConfigManager.NetValid instructions to ConfigManager.Net must begin with the All instructions support the special parameter To run the utility, call: ConfigManager.exe app.config
The best place to do this is either in the post built event of the project or as part of a build script.
InstructionsEmbeddedSection instructionXML can be specified within the comments of this instruction. This XML will be added to the configuration file if the condition parameter evaluates to true. <connectionStrings>
<!-- You can embed a section based on a condition, such as the user name. -->
<!-- #ConfigManager.Net# EmbeddedSection condition="$(Environment.UserName)==user"
<add name="MyConnectionString"
connectionString="Data Source=localhost;
Initial Catalog=MyDatabase;Integrated Security=True"
providerName="System.Data.SqlClient" />
-->
</connectionStrings>
ExternalSection instructionThis instruction copies the contents (or part of the contents) of an external file into the configuration file. If no value is supplied for the <!--Copy the appSettings from another app.config file into the current file. -->
<!-- #ConfigManager.Net# ExternalSection
source="alternative.config"
xpath="/configuration/applicationSettings/Alternative.Properties.Settings" -->
OpenSection instructionAn <connectionStrings>
<!-- #ConfigManager.Net# OpenSection condition="$(Environment.UserName)!=fergal" -->
<!-- You you can remove a section based on a condition. -->
<add name="RemoveConnectionString"
connectionString="Data Source=localhost;
Initial Catalog=MyDatabase;Integrated Security=True"
providerName="System.Data.SqlClient" />
<!-- #ConfigManager.Net# EndOpenSection -->
</connectionStrings>
SetValue instructionChanges a value within the configuration file. This can be the inner text of a node of the value of an attribute. <!-- Change the value of the UserName application setting. -->
<!-- #ConfigManager.Net# SetValue
xpath="/configuration/applicationSettings/ConfigManagerDemo.
Properties.Settings/setting[@name='UserName']/value"
value="newUser" -->
PropertiesA property can be used anywhere in an instruction. This is done by placing the property name between "$(" and ")" in the instruction. ConfigManager.Net has the following built-in instructions:
In addition to these properties, all environment variables are exposed as properties. They can be accessed as Command line propertiesAdditional properties can be passed into the ConfigManager.Net on the command line: ConfigManager.exe app.config prop1="value1" prop2="value2"
Changes
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||