繁体   English   中英

web.config文件转换

[英]web.config file transformations

我们一年几次发布产品更新,因此我们需要能够更改客户的web.configs。

我们希望能够通过c#应用这些更改。

是否有人使用ctt.exe程序并为其实现了包装器类? 在初始测试中,似乎会删除所有不理想的空格。

找到了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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM