
Setty.org
Foreword
I think that every .net developer at least once, but faced with the problems of managing configs for different environments. Often there is a need when developing a new functional opportunity to change the connection string to the database without interfering with other developers. For this, the connection string is usually changed to the local database in the config, and then these changes are committed ... All other developers are indignant because the system stopped working on their local machines.
If the command is distributed, there is often a need for specific settings. Sometimes you need the same settings for different projects in a solution and you just copy them. In the end, I would like to be able to add different logic to the config. For example, on the local developers' machines, the sent mail should be saved on disk, while on the test server, the mail should be sent using the mail sending service. I think you can give a lot of examples that are difficult to implement without an additional configs control mechanism.
Introduction
The shortcomings described in the preface led to the creation of a small OSS project called Setty. Setty generates * .config files using various “transformation languages”. The first version of the project used xslt to generate configs, and many new developers who came to our company looked at this project with fear, despite many of its advantages. Therefore, a little later we added another well-known in the .net world 'transformation language' - razor, and the ability to extend the project with any 'transformation language' without any special problems.
Installation and use
The easiest way to install is through the
plug-in for visual studio 2010. But we will go a bit more thorny and do it yourself (razor + .net 4).
- Create a project in visual studio (I created an asp.net mvc 3 project)
- Copy the web.config and add the .cshtml extension to it.
<configuration> <appSettings> <add key="MyFirstSetting" value="@Model["hello"]" /> ...
Model["hello"]
is an example of how to read settings with razor.
- Download the executable setty.exe from here and put it next to the .sln file.
- Create a folder where your key / value settings will be stored (usually it is one level above the project folder). Create an App.config file there with the appSetting section, which will be the source of settings:
<configuration> <appSettings> <add key="hello" value="Hello World"/> </appSettings> </configuration>
- Next to .sln, create a special .setty file that is needed so that the executable file knows the path to the settings. .setty - contains either an absolute or relative path to the settings.
- Upload the project to modify the * .csproj file and add the following xml to the root element:
<Target Name="Setty" BeforeTargets="PreBuildEvent"> <Exec Command=""$(MSBuildProjectDirectory)\..\setty.exe" /silent" /> </Target>
This is necessary so that before each setty regenerates configuration files.
- Download the project and perebilite it, after which your web.config file will look like this:
<configuration> <appSettings> <add key="MyFirstSetting" value="Hello World" /> ...
In real projects, the settings folder might look like this:

I believe that the hierarchical system for reading settings is understandable to every .net developer.
disadvantages
Since when using Setty your * .config files are generated before each build, the changes added to the config using NuGet can be lost. Those. developers themselves must copy these changes to * .config.cshtml files.
In * .config.cshtml, the usual highlighting for * .config files in .net is lost.
')
Additional information
1. Project site with more detailed documentation -
setty.org2. Project code and place for discussions on github -
Setty source code3. Plugin for visual studio 2010 -
VS 2010 pluginPS This project has been used in our company for several years and quite successfully.