Skip to content

Commit 27d10fd

Browse files
authored
Disallow RID on solution for MTP dotnet test (#50511)
1 parent ccff236 commit 27d10fd

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

src/Tasks/Microsoft.NET.Build.Extensions.Tasks/msbuildExtensions-ver/SolutionFile/ImportAfter/Microsoft.NET.Sdk.Solution.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Copyright (c) .NET Foundation. All rights reserved.
2121
============================================================
2222
-->
2323
<Target Name="_CheckForSolutionLevelRuntimeIdentifier"
24-
BeforeTargets="Build"
24+
BeforeTargets="Build;_MTPBuild"
2525
Condition="'$(RuntimeIdentifier)' != ''">
2626

2727
<NETSdkError ResourceName="CannotHaveSolutionLevelRuntimeIdentifier" />
@@ -30,7 +30,7 @@ Copyright (c) .NET Foundation. All rights reserved.
3030

3131

3232
<Target Name="_CheckForSolutionLevelOutputPath"
33-
BeforeTargets="Build;Publish;Clean;Store;VSTest"
33+
BeforeTargets="Build;Publish;Clean;Store;VSTest;_MTPBuild"
3434
Condition="'$(_CommandLineDefinedOutputPath)' == 'true'">
3535

3636
<NetSdkWarning ResourceName="CannotHaveSolutionLevelOutputPath" />

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,14 @@ public void RunProjectWithMultipleTFMsWithArchOption_ShouldReturnExitCodeGeneric
161161

162162
if (!TestContext.IsLocalized())
163163
{
164-
result.StdOut
165-
.Should().Contain("Test run summary: Failed!")
166-
.And.Contain("total: 14")
167-
.And.Contain("succeeded: 3")
168-
.And.Contain("failed: 8")
169-
.And.Contain("skipped: 3");
164+
result.StdOut.Should().Contain("error NETSDK1134: Building a solution with a specific RuntimeIdentifier is not supported. If you would like to publish for a single RID, specify the RID at the individual project level instead.");
165+
}
166+
else
167+
{
168+
result.StdOut.Should().Contain("NETSDK1134");
170169
}
171170

172-
result.ExitCode.Should().Be(ExitCodes.AtLeastOneTestFailed);
171+
result.ExitCode.Should().Be(ExitCodes.GenericFailure);
173172
}
174173

175174
// https://github.com/dotnet/sdk/issues/49665

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public void RunWithNonExistentSolutionPath_ShouldReturnExitCodeGenericFailure(st
218218
[InlineData(TestingConstants.Debug)]
219219
[InlineData(TestingConstants.Release)]
220220
[PlatformSpecificTheory(TestPlatforms.Any & ~TestPlatforms.OSX)]
221-
public void RunTestProjectSolutionWithArchOption_ShouldReturnExitCodeSuccess(string configuration)
221+
public void RunTestProjectWithArchOption_ShouldReturnExitCodeSuccess(string configuration)
222222
{
223223
TestAsset testInstance = _testAssetsManager.CopyTestAsset("TestProjectWithTests", Guid.NewGuid().ToString()).WithSource();
224224

@@ -235,6 +235,32 @@ public void RunTestProjectSolutionWithArchOption_ShouldReturnExitCodeSuccess(str
235235
result.ExitCode.Should().Be(ExitCodes.Success);
236236
}
237237

238+
// https://github.com/dotnet/sdk/issues/49665
239+
[InlineData(TestingConstants.Debug)]
240+
[InlineData(TestingConstants.Release)]
241+
[PlatformSpecificTheory(TestPlatforms.Any & ~TestPlatforms.OSX)]
242+
public void RunTestProjectSolutionWithArchOption_NotSupported(string configuration)
243+
{
244+
TestAsset testInstance = _testAssetsManager.CopyTestAsset("TestProjectSolution", Guid.NewGuid().ToString()).WithSource();
245+
246+
var arch = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant();
247+
CommandResult result = new DotnetTestCommand(Log, disableNewOutput: false)
248+
.WithWorkingDirectory(testInstance.Path)
249+
.Execute(CommonOptions.ArchitectureOption.Name, arch,
250+
TestingPlatformOptions.ConfigurationOption.Name, configuration);
251+
252+
if (!TestContext.IsLocalized())
253+
{
254+
result.StdOut.Should().Contain("error NETSDK1134: Building a solution with a specific RuntimeIdentifier is not supported. If you would like to publish for a single RID, specify the RID at the individual project level instead.");
255+
}
256+
else
257+
{
258+
result.StdOut.Should().Contain("NETSDK1134");
259+
}
260+
261+
result.ExitCode.Should().Be(ExitCodes.GenericFailure);
262+
}
263+
238264
// https://github.com/dotnet/sdk/issues/49665
239265
[InlineData(TestingConstants.Debug)]
240266
[InlineData(TestingConstants.Release)]

0 commit comments

Comments
 (0)