📜 ⬆️ ⬇️

Managing configuration files in .net projects

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).

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.org
2. Project code and place for discussions on github - Setty source code
3. Plugin for visual studio 2010 - VS 2010 plugin

PS This project has been used in our company for several years and quite successfully.

Source: https://habr.com/ru/post/148312/


All Articles