Skip to content

Commit 628f1b7

Browse files
CopilotYoussef1313
andcommitted
Address review feedback: remove redundant properties, create dotnet.config, revert TestApplication.cs, update test to use dedicated test asset
Co-authored-by: Youssef1313 <[email protected]>
1 parent 1758fb4 commit 628f1b7

File tree

4 files changed

+7
-118
lines changed

4 files changed

+7
-118
lines changed

src/Cli/dotnet/Commands/Test/TestApplication.cs

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
using System.Diagnostics;
77
using System.IO.Pipes;
8-
using System.Runtime.InteropServices;
98
using Microsoft.DotNet.Cli.Commands.Test.IPC;
109
using Microsoft.DotNet.Cli.Commands.Test.IPC.Models;
1110
using Microsoft.DotNet.Cli.Commands.Test.IPC.Serializers;
@@ -55,16 +54,6 @@ public async Task<int> RunAsync(TestOptions testOptions)
5554

5655
private ProcessStartInfo CreateProcessStartInfo(TestOptions testOptions)
5756
{
58-
// Check for architecture mismatch when UseAppHost=false
59-
if (ShouldValidateArchitectureForUseAppHostFalse())
60-
{
61-
var archMismatchError = ValidateArchitectureCompatibility();
62-
if (archMismatchError != null)
63-
{
64-
throw new GracefulException(archMismatchError);
65-
}
66-
}
67-
6857
var processStartInfo = new ProcessStartInfo
6958
{
7059
// We should get correct RunProperties right away.
@@ -379,103 +368,6 @@ public override string ToString()
379368
return builder.ToString();
380369
}
381370

382-
private bool ShouldValidateArchitectureForUseAppHostFalse()
383-
{
384-
// Check if UseAppHost=false (RunArguments starts with "exec")
385-
return !string.IsNullOrEmpty(Module.RunProperties.RunArguments) &&
386-
Module.RunProperties.RunArguments.TrimStart().StartsWith("exec ", StringComparison.OrdinalIgnoreCase);
387-
}
388-
389-
private string ValidateArchitectureCompatibility()
390-
{
391-
// Extract the requested architecture from MSBuild args
392-
string requestedArch = GetRequestedArchitecture();
393-
if (string.IsNullOrEmpty(requestedArch))
394-
{
395-
// No architecture specified, no validation needed
396-
return null;
397-
}
398-
399-
// Get current muxer architecture
400-
string currentArch = GetCurrentMuxerArchitecture();
401-
402-
// Normalize architecture names for comparison
403-
string normalizedRequested = NormalizeArchitectureName(requestedArch);
404-
string normalizedCurrent = NormalizeArchitectureName(currentArch);
405-
406-
if (!string.Equals(normalizedRequested, normalizedCurrent, StringComparison.OrdinalIgnoreCase))
407-
{
408-
return $"The current .NET host does not support the requested target architecture '{requestedArch}'. " +
409-
$"The current host is running '{currentArch}' architecture. " +
410-
$"When UseAppHost is false, the target architecture must match the current .NET host architecture.";
411-
}
412-
413-
return null;
414-
}
415-
416-
private string GetRequestedArchitecture()
417-
{
418-
// Look for architecture in MSBuild args
419-
foreach (var arg in _buildOptions.MSBuildArgs)
420-
{
421-
if (arg.StartsWith("--property:RuntimeIdentifier=", StringComparison.OrdinalIgnoreCase) ||
422-
arg.StartsWith("-property:RuntimeIdentifier=", StringComparison.OrdinalIgnoreCase) ||
423-
arg.StartsWith("/property:RuntimeIdentifier=", StringComparison.OrdinalIgnoreCase) ||
424-
arg.StartsWith("-p:RuntimeIdentifier=", StringComparison.OrdinalIgnoreCase) ||
425-
arg.StartsWith("/p:RuntimeIdentifier=", StringComparison.OrdinalIgnoreCase))
426-
{
427-
var rid = arg.Split('=', 2)[1];
428-
return ExtractArchitectureFromRid(rid);
429-
}
430-
}
431-
432-
// Also check UnmatchedTokens for --arch parameter
433-
for (int i = 0; i < _buildOptions.UnmatchedTokens.Count - 1; i++)
434-
{
435-
if (_buildOptions.UnmatchedTokens[i] == "--arch" || _buildOptions.UnmatchedTokens[i] == "-a")
436-
{
437-
return _buildOptions.UnmatchedTokens[i + 1];
438-
}
439-
}
440-
441-
return null;
442-
}
443-
444-
private static string ExtractArchitectureFromRid(string rid)
445-
{
446-
// RID format is typically os-arch (e.g., linux-x64, win-x86, osx-arm64)
447-
var parts = rid.Split('-');
448-
if (parts.Length >= 2)
449-
{
450-
return parts[^1]; // Last part is the architecture
451-
}
452-
return rid; // Fallback to the entire string
453-
}
454-
455-
private static string GetCurrentMuxerArchitecture()
456-
{
457-
return RuntimeInformation.ProcessArchitecture switch
458-
{
459-
Architecture.X64 => "x64",
460-
Architecture.X86 => "x86",
461-
Architecture.Arm => "arm",
462-
Architecture.Arm64 => "arm64",
463-
_ => RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant()
464-
};
465-
}
466-
467-
private static string NormalizeArchitectureName(string arch)
468-
{
469-
return arch.ToLowerInvariant() switch
470-
{
471-
"amd64" => "x64",
472-
"x86_64" => "x64",
473-
"arm64" => "arm64",
474-
"aarch64" => "arm64",
475-
_ => arch.ToLowerInvariant()
476-
};
477-
}
478-
479371
public void Dispose()
480372
{
481373
foreach (var namedPipeServer in _testAppPipeConnections)

test/TestAssets/TestProjects/TestProjectMTPWithUseAppHostFalse/TestProjectMTPWithUseAppHostFalse.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<Nullable>enable</Nullable>
1111

1212
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
13-
<IsTestingPlatformApplication>true</IsTestingPlatformApplication>
1413
</PropertyGroup>
1514

1615
<ItemGroup>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[general]
2+
telemetry-output=false
3+
4+
[testing.platform]
5+
use-microsoft-testing-platform=true

test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTests.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -379,15 +379,8 @@ public void RunningWithGlobalPropertyShouldProperlyPropagate(string configuratio
379379
[Fact]
380380
public void RunMTPProjectWithUseAppHostFalseAndArchMismatch_ShouldFailWithProperError()
381381
{
382-
TestAsset testInstance = _testAssetsManager.CopyTestAsset("TestProjectWithTests", Guid.NewGuid().ToString())
383-
.WithSource()
384-
.WithProjectChanges(project =>
385-
{
386-
// Modify the project to use UseAppHost=false
387-
var ns = project.Root!.Name.Namespace;
388-
var propertyGroup = project.Root.Elements(ns + "PropertyGroup").First();
389-
propertyGroup.Add(new XElement(ns + "UseAppHost", "false"));
390-
});
382+
TestAsset testInstance = _testAssetsManager.CopyTestAsset("TestProjectMTPWithUseAppHostFalse", Guid.NewGuid().ToString())
383+
.WithSource();
391384

392385
// Call test with wrong architecture
393386
CommandResult result = new DotnetTestCommand(Log, disableNewOutput: false)

0 commit comments

Comments
 (0)