0

年に数回、製品の更新プログラムをリリースしており、お客様の web.configs を変更できるようにする必要があります。

これらの変更を C# 経由で適用できるようにしたいと考えています。

ctt.exeプログラムを使用して、そのラッパー クラスを実装した人はいますか? 最初のテストでは、理想的ではないすべての空白を取り除くようです。

4

1 に答える 1

2

サードパーティのツールを必要とせずにこれを完全に解決する 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);
                }
于 2014-10-21T09:06:06.913 に答える