From e8e29d868ef51f6e55d71af6d729cfcd175715f4 Mon Sep 17 00:00:00 2001 From: Nathan Mytelka Date: Thu, 4 Feb 2021 11:03:34 -0800 Subject: [PATCH 1/2] Permit specifying utf8 for tool tasks --- src/Utilities/ToolTask.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Utilities/ToolTask.cs b/src/Utilities/ToolTask.cs index 23f7abc7e67..4236ef730e8 100644 --- a/src/Utilities/ToolTask.cs +++ b/src/Utilities/ToolTask.cs @@ -182,6 +182,11 @@ public virtual string ToolExe /// Path to tool. public string ToolPath { set; get; } + /// + /// Project-visible property to allow users to override the encoding method. + /// + public string UseUtf8Encoding { get; set; } = EncodingUtilities.UseUtf8Detect; + /// /// Array of equals-separated pairs of environment /// variables that should be passed to the spawned executable, @@ -1373,7 +1378,7 @@ public override bool Execute() } else { - encoding = EncodingUtilities.BatchFileEncoding(commandLineCommands + _temporaryBatchFile, EncodingUtilities.UseUtf8Detect); + encoding = EncodingUtilities.BatchFileEncoding(commandLineCommands + _temporaryBatchFile, UseUtf8Encoding); if (encoding.CodePage != EncodingUtilities.CurrentSystemOemEncoding.CodePage) { From e87a5788f8cff7fa8bfff7941edf71a6f36ec888 Mon Sep 17 00:00:00 2001 From: Nathan Mytelka Date: Mon, 22 Feb 2021 15:18:24 -0800 Subject: [PATCH 2/2] Fix without useutf8encoding in exec --- .../net/Microsoft.Build.Tasks.Core.cs | 1 - .../netstandard/Microsoft.Build.Tasks.Core.cs | 1 - .../net/Microsoft.Build.Utilities.Core.cs | 1 + .../netstandard/Microsoft.Build.Utilities.Core.cs | 1 + src/Tasks/Exec.cs | 8 -------- src/Utilities/ToolTask.cs | 5 ++++- 6 files changed, 6 insertions(+), 11 deletions(-) diff --git a/ref/Microsoft.Build.Tasks.Core/net/Microsoft.Build.Tasks.Core.cs b/ref/Microsoft.Build.Tasks.Core/net/Microsoft.Build.Tasks.Core.cs index 22723af7d9c..821755bdebb 100644 --- a/ref/Microsoft.Build.Tasks.Core/net/Microsoft.Build.Tasks.Core.cs +++ b/ref/Microsoft.Build.Tasks.Core/net/Microsoft.Build.Tasks.Core.cs @@ -333,7 +333,6 @@ public Exec() { } [Microsoft.Build.Framework.OutputAttribute] public string StdOutEncoding { get { throw null; } set { } } protected override string ToolName { get { throw null; } } - public string UseUtf8Encoding { get { throw null; } set { } } public string WorkingDirectory { get { throw null; } set { } } protected internal override void AddCommandLineCommands(Microsoft.Build.Tasks.CommandLineBuilderExtension commandLine) { } protected override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands) { throw null; } diff --git a/ref/Microsoft.Build.Tasks.Core/netstandard/Microsoft.Build.Tasks.Core.cs b/ref/Microsoft.Build.Tasks.Core/netstandard/Microsoft.Build.Tasks.Core.cs index 9ffad88021a..b91ced2cadb 100644 --- a/ref/Microsoft.Build.Tasks.Core/netstandard/Microsoft.Build.Tasks.Core.cs +++ b/ref/Microsoft.Build.Tasks.Core/netstandard/Microsoft.Build.Tasks.Core.cs @@ -263,7 +263,6 @@ public Exec() { } [Microsoft.Build.Framework.OutputAttribute] public string StdOutEncoding { get { throw null; } set { } } protected override string ToolName { get { throw null; } } - public string UseUtf8Encoding { get { throw null; } set { } } public string WorkingDirectory { get { throw null; } set { } } protected internal override void AddCommandLineCommands(Microsoft.Build.Tasks.CommandLineBuilderExtension commandLine) { } protected override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands) { throw null; } diff --git a/ref/Microsoft.Build.Utilities.Core/net/Microsoft.Build.Utilities.Core.cs b/ref/Microsoft.Build.Utilities.Core/net/Microsoft.Build.Utilities.Core.cs index 40abd53b294..f98536f413d 100644 --- a/ref/Microsoft.Build.Utilities.Core/net/Microsoft.Build.Utilities.Core.cs +++ b/ref/Microsoft.Build.Utilities.Core/net/Microsoft.Build.Utilities.Core.cs @@ -555,6 +555,7 @@ protected ToolTask(System.Resources.ResourceManager taskResources, string helpKe protected abstract string ToolName { get; } public string ToolPath { get { throw null; } set { } } public bool UseCommandProcessor { get { throw null; } set { } } + public string UseUtf8Encoding { get { throw null; } set { } } public bool YieldDuringToolExecution { get { throw null; } set { } } protected virtual string AdjustCommandsForOperatingSystem(string input) { throw null; } protected virtual bool CallHostObjectToExecute() { throw null; } diff --git a/ref/Microsoft.Build.Utilities.Core/netstandard/Microsoft.Build.Utilities.Core.cs b/ref/Microsoft.Build.Utilities.Core/netstandard/Microsoft.Build.Utilities.Core.cs index e6cc6f3fa50..27729fa1350 100644 --- a/ref/Microsoft.Build.Utilities.Core/netstandard/Microsoft.Build.Utilities.Core.cs +++ b/ref/Microsoft.Build.Utilities.Core/netstandard/Microsoft.Build.Utilities.Core.cs @@ -395,6 +395,7 @@ protected ToolTask(System.Resources.ResourceManager taskResources, string helpKe protected abstract string ToolName { get; } public string ToolPath { get { throw null; } set { } } public bool UseCommandProcessor { get { throw null; } set { } } + public string UseUtf8Encoding { get { throw null; } set { } } public bool YieldDuringToolExecution { get { throw null; } set { } } protected virtual string AdjustCommandsForOperatingSystem(string input) { throw null; } protected virtual bool CallHostObjectToExecute() { throw null; } diff --git a/src/Tasks/Exec.cs b/src/Tasks/Exec.cs index 0cf22b566c5..2132b8266db 100644 --- a/src/Tasks/Exec.cs +++ b/src/Tasks/Exec.cs @@ -123,14 +123,6 @@ public string CustomWarningRegularExpression /// protected override Encoding StandardErrorEncoding => _standardErrorEncoding; - /// - /// Whether or not to use UTF8 encoding for the cmd file and console window. - /// Values: Always, Never, Detect - /// If set to Detect, the current code page will be used unless it cannot represent - /// the Command string. In that case, UTF-8 is used. - /// - public string UseUtf8Encoding { get; set; } - /// /// Project visible property specifying the encoding of the captured task standard output stream /// diff --git a/src/Utilities/ToolTask.cs b/src/Utilities/ToolTask.cs index 4236ef730e8..08caefbd810 100644 --- a/src/Utilities/ToolTask.cs +++ b/src/Utilities/ToolTask.cs @@ -183,7 +183,10 @@ public virtual string ToolExe public string ToolPath { set; get; } /// - /// Project-visible property to allow users to override the encoding method. + /// Whether or not to use UTF8 encoding for the cmd file and console window. + /// Values: Always, Never, Detect + /// If set to Detect, the current code page will be used unless it cannot represent + /// the Command string. In that case, UTF-8 is used. /// public string UseUtf8Encoding { get; set; } = EncodingUtilities.UseUtf8Detect;