From cb8b5f3812d483710953aee698e33110be86cabe Mon Sep 17 00:00:00 2001 From: Renaud Paquay Date: Mon, 6 Dec 2010 22:03:10 -0800 Subject: [PATCH] Delete 'Trust Level="Medium"' element for package --HG-- branch : dev --- Orchard.proj | 8 ++- .../MSBuild.Orchard.Tasks.csproj | 1 + src/Tools/MSBuild.Orchard.Tasks/XmlDelete.cs | 52 +++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 src/Tools/MSBuild.Orchard.Tasks/XmlDelete.cs diff --git a/Orchard.proj b/Orchard.proj index baa1d2e7b..02f327e21 100644 --- a/Orchard.proj +++ b/Orchard.proj @@ -134,6 +134,7 @@ + @@ -207,6 +208,9 @@ XPath="/configuration/system.web/compilation/@debug" Value="false" /> + + @@ -215,13 +219,13 @@ XPath="/configuration/system.web/machineKey/@decryptionKey" Value="AutoGenerate" /> - + Value="Error" />--> + diff --git a/src/Tools/MSBuild.Orchard.Tasks/XmlDelete.cs b/src/Tools/MSBuild.Orchard.Tasks/XmlDelete.cs new file mode 100644 index 000000000..207d05231 --- /dev/null +++ b/src/Tools/MSBuild.Orchard.Tasks/XmlDelete.cs @@ -0,0 +1,52 @@ +using System; +using System.Text; +using System.Xml; +using System.Xml.XPath; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; + +namespace MSBuild.Orchard.Tasks { + public class XmlDelete : Task { + + public string Namespace { get; set; } + public string Prefix { get; set; } + [Required] + public string XmlFileName { get; set; } + [Required] + public string XPath { get; set; } + + public override bool Execute() { + try { + var document = new XmlDocument(); + document.Load(this.XmlFileName); + + var navigator = document.CreateNavigator(); + var nsResolver = new XmlNamespaceManager(navigator.NameTable); + + if (!string.IsNullOrEmpty(this.Prefix) && !string.IsNullOrEmpty(this.Namespace)) { + nsResolver.AddNamespace(this.Prefix, this.Namespace); + } + + var expr = XPathExpression.Compile(this.XPath, nsResolver); + + var iterator = navigator.Select(expr); + while (iterator.MoveNext()) { + iterator.Current.DeleteSelf(); + } + + using (var writer = new XmlTextWriter(this.XmlFileName, Encoding.UTF8)) { + writer.Formatting = Formatting.Indented; + document.Save(writer); + writer.Close(); + } + } + catch (Exception exception) { + base.Log.LogErrorFromException(exception); + return false; + } + base.Log.LogMessage("Updated file '{0}'", new object[] { this.XmlFileName }); + return true; + } + } +} +