public MSBuildXmlTransformer()
 {
     _xfrm = new Microsoft.Web.Publishing.Tasks.TransformXml
     {
         BuildEngine = new XmlTransformerEngineStub()
     };
 }
Exemple #2
0
 public MSBuildXmlTransformer()
 {
     _xfrm = new Microsoft.Web.Publishing.Tasks.TransformXml
     {
         BuildEngine = new XmlTransformerEngineStub()
     };
 }
        public override bool Execute()
        {
            Log.LogMessage("Begin TransformXmlFiles");

            if (TransformFiles?.Any() ?? false)
            {
                Log.LogMessage("Creating Microsoft.Web.Publishing.Tasks.TransformXml");
                var transform = new Microsoft.Web.Publishing.Tasks.TransformXml()
                {
                    BuildEngine = BuildEngine,
                    HostObject  = HostObject
                };

                foreach (var inputFile in TransformFiles)
                {
                    Log.LogMessage($"Preparing to transform '{inputFile.ItemSpec}'");

                    //Get the env name
                    var fileParts = Path.GetFileNameWithoutExtension(inputFile.ItemSpec).Split('.');
                    var envName   = fileParts.LastOrDefault();

                    //Build output directory as base output directory plus environment plus project (if supplied)
                    var outDir = Path.Combine(OutputDirectory, envName);
                    if (!String.IsNullOrEmpty(ProjectName))
                    {
                        outDir = Path.Combine(outDir, ProjectName);
                    }

                    //Build the output path
                    var outFile = Path.Combine(outDir, TargetFile);

                    //Make sure the directory exists
                    if (!Directory.Exists(outDir))
                    {
                        Log.LogMessage($"Creating directory '{outDir}'");
                        Directory.CreateDirectory(outDir);
                    }
                    ;

                    //Transform the config
                    transform.Destination = outFile;
                    transform.Source      = SourceFile;
                    transform.Transform   = inputFile.ItemSpec;

                    Log.LogMessage($"Transforming file");
                    if (!transform.Execute())
                    {
                        Log.LogError($"Error transforming file");
                        return(false);
                    }
                    ;
                }
                ;
            }
            ;

            Log.LogMessage("End TransformXmlFiles");
            return(true);
        }