Skip to content

Commit b9b6f4a

Browse files
Read RunSettingsFilePath property and send as env var in dotnet test (#43868)
1 parent e25de7d commit b9b6f4a

File tree

8 files changed

+18
-7
lines changed

8 files changed

+18
-7
lines changed

src/Cli/dotnet/commands/dotnet-test/IPC/Models/ModuleMessage.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
namespace Microsoft.DotNet.Tools.Test;
77

8-
internal sealed record ModuleMessage(string? DLLPath, string? ProjectPath, string? TargetFramework) : IRequest;
8+
internal sealed record ModuleMessage(string? DLLPath, string? ProjectPath, string? TargetFramework, string? RunSettingsFilePath) : IRequest;

src/Cli/dotnet/commands/dotnet-test/IPC/Serializers/ModuleMessageSerializer.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ public object Deserialize(Stream stream)
1212
string modulePath = ReadString(stream);
1313
string projectPath = ReadString(stream);
1414
string targetFramework = ReadString(stream);
15-
return new ModuleMessage(modulePath.Trim(), projectPath.Trim(), targetFramework.Trim());
15+
string runSettingsFilePath = ReadString(stream);
16+
return new ModuleMessage(modulePath.Trim(), projectPath.Trim(), targetFramework.Trim(), runSettingsFilePath.Trim());
1617
}
1718

1819
public void Serialize(object objectToSerialize, Stream stream)
1920
{
2021
WriteString(stream, ((ModuleMessage)objectToSerialize).DLLPath);
2122
WriteString(stream, ((ModuleMessage)objectToSerialize).ProjectPath);
2223
WriteString(stream, ((ModuleMessage)objectToSerialize).TargetFramework);
24+
WriteString(stream, ((ModuleMessage)objectToSerialize).RunSettingsFilePath);
2325
}
2426
}
2527
}

src/Cli/dotnet/commands/dotnet-test/MSBuildConnectionHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private Task<IResponse> OnRequest(IRequest request)
6262
throw new NotSupportedException($"Request '{request.GetType()}' is unsupported.");
6363
}
6464

65-
var testApp = new TestApplication(new Module(module.DLLPath, module.ProjectPath, module.TargetFramework), _args);
65+
var testApp = new TestApplication(new Module(module.DLLPath, module.ProjectPath, module.TargetFramework, module.RunSettingsFilePath), _args);
6666
// Write the test application to the channel
6767
_actionQueue.Enqueue(testApp);
6868
}

src/Cli/dotnet/commands/dotnet-test/Models.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Microsoft.DotNet.Cli
77
{
8-
internal sealed record Module(string? DLLOrExe, string? ProjectPath, string? TargetFramework);
8+
internal sealed record Module(string? DLLOrExe, string? ProjectPath, string? TargetFramework, string? RunSettingsFilePath);
99

1010
internal sealed record Handshake(Dictionary<byte, string>? Properties);
1111

src/Cli/dotnet/commands/dotnet-test/TestApplication.cs

+6
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public async Task<int> RunAsync(bool isFilterMode, bool enableHelp, BuiltInOptio
5656
}
5757

5858
bool isDll = _module.DLLOrExe.EndsWith(".dll");
59+
5960
ProcessStartInfo processStartInfo = new()
6061
{
6162
FileName = isFilterMode ? isDll ? Environment.ProcessPath : _module.DLLOrExe : Environment.ProcessPath,
@@ -64,6 +65,11 @@ public async Task<int> RunAsync(bool isFilterMode, bool enableHelp, BuiltInOptio
6465
RedirectStandardError = true
6566
};
6667

68+
if (!string.IsNullOrEmpty(_module.RunSettingsFilePath))
69+
{
70+
processStartInfo.EnvironmentVariables.Add("TESTINGPLATFORM_VSTESTBRIDGE_RUNSETTINGS_FILE", _module.RunSettingsFilePath);
71+
}
72+
6773
_namedPipeConnectionLoop = Task.Run(async () => await WaitConnectionAsync(_cancellationToken.Token), _cancellationToken.Token);
6874
var result = await StartProcess(processStartInfo);
6975

src/Cli/dotnet/commands/dotnet-test/TestModulesFilterHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public bool RunWithTestModulesFilter(ParseResult parseResult)
5050

5151
foreach (string testModule in testModulePaths)
5252
{
53-
var testApp = new TestApplication(new Module(testModule, null, null), _args);
53+
var testApp = new TestApplication(new Module(testModule, null, null, null), _args);
5454
// Write the test application to the channel
5555
_actionQueue.Enqueue(testApp);
5656
}

src/Layout/redist/MSBuildImports/Current/Microsoft.Common.targets/ImportAfter/Microsoft.TestPlatform.ImportAfter.targets

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ Copyright (c) .NET Foundation. All rights reserved.
2020
<!-- Register TestingPlatform task -->
2121
<UsingTask TaskName="GetTestsProject" AssemblyFile="$(MicrosoftNETBuildTasksDirectory)Microsoft.NET.Build.Tasks.dll" />
2222
<Target Name="_GetTestsProject" Condition=" $(IsTestProject) == 'true' OR '$(IsTestingPlatformApplication)' == 'true' " >
23-
<GetTestsProject TargetPath="$(TargetPath)" GetTestsProjectPipeName="$(GetTestsProjectPipeName)" ProjectFullPath="$(MSBuildProjectFullPath)" TargetFramework="$(TargetFramework)" />
23+
<GetTestsProject TargetPath="$(TargetPath)" GetTestsProjectPipeName="$(GetTestsProjectPipeName)" ProjectFullPath="$(MSBuildProjectFullPath)" TargetFramework="$(TargetFramework)" RunSettingsFilePath="$(RunSettingsFilePath)" />
2424
</Target>
2525
</Project>

src/Tasks/Microsoft.NET.Build.Tasks/GetTestsProject.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
44

55
using Microsoft.Build.Framework;
6+
using Microsoft.Build.Utilities;
67
using Microsoft.DotNet.Tools.Test;
78

89
namespace Microsoft.NET.Build.Tasks
@@ -21,6 +22,8 @@ public class GetTestsProject : Microsoft.Build.Utilities.Task
2122
[Required]
2223
public ITaskItem TargetFramework { get; set; }
2324

25+
public ITaskItem RunSettingsFilePath { get; set; } = new TaskItem(string.Empty);
26+
2427
public override bool Execute()
2528
{
2629
try
@@ -33,7 +36,7 @@ public override bool Execute()
3336
dotnetTestPipeClient.RegisterSerializer(new VoidResponseSerializer(), typeof(VoidResponse));
3437

3538
dotnetTestPipeClient.ConnectAsync(CancellationToken.None).GetAwaiter().GetResult();
36-
dotnetTestPipeClient.RequestReplyAsync<ModuleMessage, VoidResponse>(new ModuleMessage(TargetPath.ItemSpec, ProjectFullPath.ItemSpec, TargetFramework.ItemSpec), CancellationToken.None).GetAwaiter().GetResult();
39+
dotnetTestPipeClient.RequestReplyAsync<ModuleMessage, VoidResponse>(new ModuleMessage(TargetPath.ItemSpec, ProjectFullPath.ItemSpec, TargetFramework.ItemSpec, RunSettingsFilePath.ItemSpec), CancellationToken.None).GetAwaiter().GetResult();
3740
}
3841
catch (Exception ex)
3942
{

0 commit comments

Comments
 (0)