Skip to content

Instantly share code, notes, and snippets.

@gazlu
Last active December 27, 2016 17:35
Show Gist options
  • Save gazlu/2ee41254c91ae9daa177aeeb58c4a3d0 to your computer and use it in GitHub Desktop.
Save gazlu/2ee41254c91ae9daa177aeeb58c4a3d0 to your computer and use it in GitHub Desktop.
Configuration File transformer, easy to integrate config transformation with build systems
// You need to install 'Microsoft.Web.Xdt' from nuget ==> Install-Package Microsoft.Web.Xdt
using System;
using System.Reflection;
using Microsoft.Web.XmlTransform;
namespace ConfigTransformer
{
internal class Program
{
private enum ExitCode : int
{
Success = 0,
InvalidParameters = 1
}
private static int Main(string[] args)
{
var version = Assembly.GetEntryAssembly().GetName().Version;
Console.WriteLine(
"==================\n"
+ string.Format(" Config Transformer v{0}.{1}\n", version.Major, version.Minor)
+ "==================\n");
if (args == null || args.Length != 3)
{
Console.WriteLine(
"Error: Unexpected number of paramters.\n"
+ "Usage: ConfigTransformer source-file transform-file output-file\n"
+ " source-file : (Input) The original config file\n"
+ " transform-file : (Input) The transform config file\n"
+ " output-file : (Output) The output config file\n");
return (int)ExitCode.InvalidParameters;
}
Console.WriteLine("- Applying transform to source . . .\n");
var source = new XmlTransformableDocument();
source.Load(args[0]);
var transform = new XmlTransformation(args[1]);
transform.Apply(source);
source.Save(args[2]);
return (int)ExitCode.Success;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment