Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

ConfigurationTransformations Nuget

0.00/5 (No votes)
24 Apr 2015 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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here