public static string ReplaceNuspecValues(string nuspecContent, string newId, string newVersion, string newAuthors, string newTags, string newProjectUrl, string newDescription)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(nuspecContent);
XmlNamespaceManager xnm = new XmlNamespaceManager(xmlDoc.NameTable);
xnm.AddNamespace("ns", "http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd");
UpdateInnerText(xmlDoc, "//ns:id/text()", xnm, newId);
UpdateInnerText(xmlDoc, "//ns:version/text()", xnm, newVersion);
UpdateInnerText(xmlDoc, "//ns:authors/text()", xnm, newAuthors);
UpdateInnerText(xmlDoc, "//ns:tags/text()", xnm, newTags);
UpdateInnerText(xmlDoc, "//ns:projectUrl/text()", xnm, newProjectUrl);
UpdateInnerText(xmlDoc, "//ns:description/text()", xnm, newDescription);
return xmlDoc.OuterXml;
}
public static void UpdateInnerText(XmlDocument xmlDoc, string xpath, XmlNamespaceManager xnm, string newValue)
{
XmlNode node = xmlDoc.SelectSingleNode(xpath, xnm);
if (node != null)
{
node.InnerText = newValue;
}
}