簡體   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