[英]web.config file transformations
找到了Microsoft.Web.XmlTransform库,该库可以完美解决此问题,而无需第三方工具。
using Microsoft.Web.XmlTransform;
...
using (XmlTransformableDocument document = new XmlTransformableDocument())
using (XmlTransformation transformation = new XmlTransformation(transformFilePath))
{
document.PreserveWhitespace = true;
document.Load(sourceFilePath);
var success = transformation.Apply(document);
if (!success)
{
string message = string.Format(
"There was an unknown error trying while trying to apply the transform. Source file='{0}',Transform='{1}', Destination='{2}'",
sourceFilePath, transformFilePath, destinationFilePath);
throw new Exception(message);
}
document.Save(destinationFilePath);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.