diff --git a/src/Cli/Microsoft.DotNet.Cli.Utils/BuiltInCommand.cs b/src/Cli/Microsoft.DotNet.Cli.Utils/BuiltInCommand.cs
index b50d1e7a00a3..4bf3d94e2773 100644
--- a/src/Cli/Microsoft.DotNet.Cli.Utils/BuiltInCommand.cs
+++ b/src/Cli/Microsoft.DotNet.Cli.Utils/BuiltInCommand.cs
@@ -181,4 +181,9 @@ public ICommand SetCommandArgs(string commandArgs)
{
throw new NotImplementedException();
}
+
+ public ICommand StandardOutputEncoding(Encoding encoding)
+ {
+ throw new NotImplementedException();
+ }
}
diff --git a/src/Cli/Microsoft.DotNet.Cli.Utils/Command.cs b/src/Cli/Microsoft.DotNet.Cli.Utils/Command.cs
index ac371090b91a..fa5435ec5640 100644
--- a/src/Cli/Microsoft.DotNet.Cli.Utils/Command.cs
+++ b/src/Cli/Microsoft.DotNet.Cli.Utils/Command.cs
@@ -101,6 +101,12 @@ public ICommand EnvironmentVariable(string name, string? value)
return this;
}
+ public ICommand StandardOutputEncoding(Encoding encoding)
+ {
+ _process.StartInfo.StandardOutputEncoding = encoding;
+ return this;
+ }
+
public ICommand CaptureStdOut()
{
ThrowIfRunning();
diff --git a/src/Cli/Microsoft.DotNet.Cli.Utils/ICommand.cs b/src/Cli/Microsoft.DotNet.Cli.Utils/ICommand.cs
index 0d33f0379d59..6e9856a5297a 100644
--- a/src/Cli/Microsoft.DotNet.Cli.Utils/ICommand.cs
+++ b/src/Cli/Microsoft.DotNet.Cli.Utils/ICommand.cs
@@ -25,6 +25,8 @@ public interface ICommand
ICommand SetCommandArgs(string commandArgs);
+ ICommand StandardOutputEncoding(Encoding encoding);
+
string CommandName { get; }
string CommandArgs { get; }
diff --git a/src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs b/src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs
index 3758f0456363..149490e4a5e1 100644
--- a/src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs
+++ b/src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs
@@ -87,7 +87,6 @@ public VirtualProjectBuildingCommand(
public override int Execute()
{
Debug.Assert(!(NoRestore && NoBuild));
-
var consoleLogger = RunCommand.MakeTerminalLogger(Verbosity);
var binaryLogger = GetBinaryLogger(BinaryLoggerArgs);
@@ -625,6 +624,15 @@ public static void WriteProjectFile(
""");
+ var targetDirectory = Path.GetDirectoryName(targetFilePath) ?? "";
+ writer.WriteLine($"""
+
+
+
+
+
+ """);
+
foreach (var sdk in sdkDirectives)
{
WriteImport(writer, "Sdk.targets", sdk);
diff --git a/test/Microsoft.NET.TestFramework/Commands/TestCommand.cs b/test/Microsoft.NET.TestFramework/Commands/TestCommand.cs
index 952bf87e76a8..253be67aed20 100644
--- a/test/Microsoft.NET.TestFramework/Commands/TestCommand.cs
+++ b/test/Microsoft.NET.TestFramework/Commands/TestCommand.cs
@@ -26,6 +26,8 @@ public abstract class TestCommand
public Action? CommandOutputHandler { get; set; }
public Action? ProcessStartedHandler { get; set; }
+ public Encoding? StandardOutputEncoding { get; set; }
+
protected TestCommand(ITestOutputHelper log)
{
Log = log;
@@ -57,6 +59,12 @@ public TestCommand WithStandardInput(string stdin)
return this;
}
+ public TestCommand WithStandardOutputEncoding(Encoding encoding)
+ {
+ StandardOutputEncoding = encoding;
+ return this;
+ }
+
///
/// Instructs not to escape the arguments when launching command.
/// This may be used to pass ready arguments line as single string argument.
@@ -153,6 +161,11 @@ public virtual CommandResult Execute(IEnumerable args)
{
Log.WriteLine($"❌{line}");
});
+
+ if (StandardOutputEncoding is not null)
+ {
+ command.StandardOutputEncoding(StandardOutputEncoding);
+ }
string fileToShow = Path.GetFileNameWithoutExtension(spec.FileName!).Equals("dotnet", StringComparison.OrdinalIgnoreCase) ?
"dotnet" :
diff --git a/test/dotnet.Tests/CommandTests/Run/RunFileTests.cs b/test/dotnet.Tests/CommandTests/Run/RunFileTests.cs
index 45d3dba46a3d..c99f4e8c7329 100644
--- a/test/dotnet.Tests/CommandTests/Run/RunFileTests.cs
+++ b/test/dotnet.Tests/CommandTests/Run/RunFileTests.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Runtime.Versioning;
@@ -1246,6 +1246,11 @@ public void Api()
+
+
+
+
+
@@ -1329,6 +1334,11 @@ public void Api_Diagnostic_01()
+
+
+
+
+