From 32703b6de7606b239b75937e13e8d14f887f0d06 Mon Sep 17 00:00:00 2001 From: Hawkwood Date: Sun, 19 May 2019 22:15:21 -0400 Subject: [PATCH] Fixed Scripty Issue #124: Settings encoding problem --- src/Scripty.MsBuild/ScriptyTask.cs | 6 ++++++ src/Scripty/Settings.cs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/Scripty.MsBuild/ScriptyTask.cs b/src/Scripty.MsBuild/ScriptyTask.cs index c44bfc5..ecdc16a 100644 --- a/src/Scripty.MsBuild/ScriptyTask.cs +++ b/src/Scripty.MsBuild/ScriptyTask.cs @@ -72,6 +72,12 @@ public override bool Execute() return false; } + // Some build environments by default use non-UTF8 character encodings. This + // fixes issues in those environments by forcing the character encoding to match + // the decoding in the target process. + Console.InputEncoding = Encoding.UTF8; + Console.OutputEncoding = Encoding.UTF8; + // Kick off the evaluation process, which must be done in a seperate process space // otherwise MSBuild complains when we construct the Roslyn workspace project since // it uses MSBuild to figure out what the project contains and MSBuild only supports diff --git a/src/Scripty/Settings.cs b/src/Scripty/Settings.cs index 90f1c6a..8abcfa9 100644 --- a/src/Scripty/Settings.cs +++ b/src/Scripty/Settings.cs @@ -64,6 +64,12 @@ private KeyValuePair ParseProperty(string argument) public void ReadStdin() { + // Some build environments by default use non-UTF8 character encodings. This + // fixes issues in those environments by forcing the character encoding to match + // the decoding in the target process. + Console.InputEncoding = Encoding.UTF8; + Console.OutputEncoding = Encoding.UTF8; + string stdin = Console.In.ReadToEnd(); JsonConvert.PopulateObject(stdin, this); }