Web.Config transforms outside of Microsoft MSBuild?

后端 未结 8 2093
情书的邮戳
情书的邮戳 2020-11-29 18:13

Is it possible to use Microsoft\'s XML document transform, for preparing web.configs, outside of MSBuild? I would like to use PowerShell to do these transform without having

8条回答
  •  离开以前
    2020-11-29 18:50

    Based on Michel's answer I wrote a C# function that will accomplish the same.

    Of course you could invoke the resultant DLL with PowerShell, but I was actually looking for a fully programatic version, so here it is, in case anybody else is looking for similar solution:

    using Microsoft.Web.XmlTransform;
    
    ...
    
    public static void TransformConfig(string configFileName, string transformFileName)
    {
         var document = new XmlTransformableDocument();
         document.PreserveWhitespace = true;
         document.Load(configFileName);
    
         var transformation = new XmlTransformation(transformFileName);
         if (!transformation.Apply(document))
         {
             throw new Exception("Transformation Failed");
         }
         document.Save(configFileName);
    }
    

    You will just need to include reference to following:

    C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.XmlTransform.dll

提交回复
热议问题