Skip to content

Commit

Permalink
Fix explicit NuGet version tool corrupting package
Browse files Browse the repository at this point in the history
UTF-16 in the nuspec won't load with NuGet, so force it to UTF-8.
  • Loading branch information
jonorossi committed Sep 28, 2017
1 parent c64711e commit 6fb2df5
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions tools/Explicit.NuGet.Versions/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private static void UpdateNuspecManifestContent(Dictionary<string, NuspecContent
SetPackageDepencyVersionsToBeExplicitForXmlDocument(nuspecXmlDocument, dependencyNugetId);

string updatedNuspecXml;
using (var writer = new StringWriter(new StringBuilder()))
using (var writer = new StringWriterWithEncoding(Encoding.UTF8))
using (var xmlWriter = new XmlTextWriter(writer) { Formatting = Formatting.Indented })
{
nuspecXmlDocument.Save(xmlWriter);
Expand All @@ -60,7 +60,9 @@ private static void SetPackageDepencyVersionsToBeExplicitForXmlDocument(XmlDocum
{
var currentVersion = node.Attributes["version"].Value;
if (!node.Attributes["version"].Value.StartsWith("[") && !node.Attributes["version"].Value.EndsWith("]"))
{
node.Attributes["version"].Value = $"[{currentVersion}]";
}
}
});
}
Expand Down Expand Up @@ -102,4 +104,19 @@ private static void WalkDocumentNodes(XmlNodeList nodes, Action<XmlNode> callbac
}
}
}
}

public sealed class StringWriterWithEncoding : StringWriter
{
private readonly Encoding encoding;

public StringWriterWithEncoding(Encoding encoding)
{
this.encoding = encoding;
}

public override Encoding Encoding
{
get { return encoding; }
}
}
}

0 comments on commit 6fb2df5

Please sign in to comment.