diff --git a/test/dotnet.Tests/CommandTests/Run/RunFileTestBase.cs b/test/dotnet.Tests/CommandTests/Run/RunFileTestBase.cs index 4cc89bdd49a3..d249cddc1276 100644 --- a/test/dotnet.Tests/CommandTests/Run/RunFileTestBase.cs +++ b/test/dotnet.Tests/CommandTests/Run/RunFileTestBase.cs @@ -5,13 +5,35 @@ using Microsoft.Build.Logging.StructuredLogger; using Microsoft.DotNet.Cli.Commands; using Microsoft.DotNet.Cli.Commands.Run; -using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.FileBasedPrograms; using Microsoft.DotNet.ProjectTools; +using Xunit.Sdk; namespace Microsoft.DotNet.Cli.Run.Tests; -public abstract class RunFileTestBase(ITestOutputHelper log) : SdkTest(log) +public sealed class RunFileTestFixture(IMessageSink sink) : IAsyncLifetime +{ + public ValueTask InitializeAsync() + { + RunFileTestBase.CopyNuGetConfigToRunfileDirectory(); + + // Ensure a simple app runs fully with MSBuild before running other csc-only tests + // so we have packages like ILLink.Tasks restored and csc-only optimization can kick in. + new DotnetCommand(new SharedTestOutputHelper(sink), "run", "-") + .WithStandardInput(""" + Console.WriteLine("Hello"); + """) + .Execute() + .Should().Pass() + .And.HaveStdOut("Hello"); + + return default; + } + + public ValueTask DisposeAsync() => default; +} + +public abstract class RunFileTestBase(ITestOutputHelper log) : SdkTest(log), IClassFixture { internal static string s_includeExcludeDefaultKnownExtensions => field ??= string.Join(", ", CSharpDirective.IncludeOrExclude.DefaultMapping.Select(static e => e.Extension)); @@ -140,7 +162,7 @@ private static string PrepareOutOfTreeBaseDirectory() /// is created under this directory, and NuGet walks up from the project location to /// find config files. /// - protected static void CopyNuGetConfigToRunfileDirectory() + internal static void CopyNuGetConfigToRunfileDirectory() { var sourceNuGetConfig = Path.Join(SdkTestContext.Current.TestExecutionDirectory, "NuGet.config"); var runfileDir = VirtualProjectBuilder.GetTempSubdirectory();