Skip to content

Commit

Permalink
Permit specifying that we should use utf-8 in ToolTask (#6188)
Browse files Browse the repository at this point in the history
  • Loading branch information
Forgind committed Mar 3, 2021
1 parent 4e1e167 commit 30a79b0
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
8 changes: 0 additions & 8 deletions src/Tasks/Exec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,6 @@ public string CustomWarningRegularExpression
/// </summary>
protected override Encoding StandardErrorEncoding => _standardErrorEncoding;

/// <summary>
/// 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.
/// </summary>
public string UseUtf8Encoding { get; set; }

/// <summary>
/// Project visible property specifying the encoding of the captured task standard output stream
/// </summary>
Expand Down
10 changes: 9 additions & 1 deletion src/Utilities/ToolTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ public virtual string ToolExe
/// <value>Path to tool.</value>
public string ToolPath { set; get; }

/// <summary>
/// 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.
/// </summary>
public string UseUtf8Encoding { get; set; } = EncodingUtilities.UseUtf8Detect;

/// <summary>
/// Array of equals-separated pairs of environment
/// variables that should be passed to the spawned executable,
Expand Down Expand Up @@ -1372,7 +1380,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)
{
Expand Down

0 comments on commit 30a79b0

Please sign in to comment.