Click here to Skip to main content
15,886,110 members
Articles / Programming Languages / C#

ConfigurationTransformations Nuget

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
24 Apr 2015CPOL 9.8K   6   3   2
ConfigurationTransformations Nuget

As in my recent work, I had to deal with some configuration transformations from C# code, I've created a nuget that can be used if you want to apply a transformation programmatically. To do that, you can install the ConfigurationTransformation package from the official nuget repository.
In order to use it, you can call the following from the package manager console...

PowerShell
PM> Install-Package ConfigurationTransformations

...and then just create an instance of the ConfigTransformer class to apply the transformation.

C#
ConfigTransformer configTransformer = new ConfigTransformer();
string sourceFile = @"C:\temp\web.config";
string transformationFile = @"C:\temp\web.Release.config";
string destinationFile = @"C:\temp\resultweb.config";
TransformationResult transformationResult = 
	configTransformer.ApplyTransformation(sourceFile, transformationFile, destinationFile);

If you don't specify the destination file, the source file content will be changed with the result transformed content.

The other option is to get the result content without saving it to a file:

C#
ConfigTransformer configTransformer = new ConfigTransformer();
string sourceFile = @"C:\temp\web.config";
string transformationFile = @"C:\temp\web.Release.config";
string transformedContent = configTransformer.GetTransformedFileContent(sourceFile, transformationFile);

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Telerik
Bulgaria Bulgaria
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionUhhh. What is a TransformationConfiguration Class Pin
Michael Breeden27-Apr-15 8:02
Michael Breeden27-Apr-15 8:02 
[Sorry, I meant what is a ConfigTransformer class?]

Is that a Dictionary or perhaps a System.Collections.Specialized.NameValueCollection as in
System.Collections.Specialized.NameValueCollection nvc = ConfigurationManager.AppSettings;

This article is a bit thin, but I'm listening

AnswerRe: Uhhh. What is a TransformationConfiguration Class Pin
Vasil Trifonov4-May-15 5:30
Vasil Trifonov4-May-15 5:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.