[英]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.