Last active
December 27, 2016 17:35
-
-
Save gazlu/2ee41254c91ae9daa177aeeb58c4a3d0 to your computer and use it in GitHub Desktop.
Configuration File transformer, easy to integrate config transformation with build systems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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