Skip to content

Commit 6fb2df5

Browse files
committed
Fix explicit NuGet version tool corrupting package
UTF-16 in the nuspec won't load with NuGet, so force it to UTF-8.
1 parent c64711e commit 6fb2df5

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

tools/Explicit.NuGet.Versions/Program.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private static void UpdateNuspecManifestContent(Dictionary<string, NuspecContent
4141
SetPackageDepencyVersionsToBeExplicitForXmlDocument(nuspecXmlDocument, dependencyNugetId);
4242

4343
string updatedNuspecXml;
44-
using (var writer = new StringWriter(new StringBuilder()))
44+
using (var writer = new StringWriterWithEncoding(Encoding.UTF8))
4545
using (var xmlWriter = new XmlTextWriter(writer) { Formatting = Formatting.Indented })
4646
{
4747
nuspecXmlDocument.Save(xmlWriter);
@@ -60,7 +60,9 @@ private static void SetPackageDepencyVersionsToBeExplicitForXmlDocument(XmlDocum
6060
{
6161
var currentVersion = node.Attributes["version"].Value;
6262
if (!node.Attributes["version"].Value.StartsWith("[") && !node.Attributes["version"].Value.EndsWith("]"))
63+
{
6364
node.Attributes["version"].Value = $"[{currentVersion}]";
65+
}
6466
}
6567
});
6668
}
@@ -102,4 +104,19 @@ private static void WalkDocumentNodes(XmlNodeList nodes, Action<XmlNode> callbac
102104
}
103105
}
104106
}
105-
}
107+
108+
public sealed class StringWriterWithEncoding : StringWriter
109+
{
110+
private readonly Encoding encoding;
111+
112+
public StringWriterWithEncoding(Encoding encoding)
113+
{
114+
this.encoding = encoding;
115+
}
116+
117+
public override Encoding Encoding
118+
{
119+
get { return encoding; }
120+
}
121+
}
122+
}

0 commit comments

Comments
 (0)