Skip to content

Commit 2cc87e7

Browse files
committed
Adjust, and add test
1 parent 713ebba commit 2cc87e7

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ Copyright (c) .NET Foundation. All rights reserved.
115115
<!-- Set the IsRidAgnostic property if this project should NOT accept global RuntimeIdentifier and SelfContained
116116
property values from referencing projects. -->
117117
<PropertyGroup Condition="'$(IsRidAgnostic)' == ''">
118-
<IsRidAgnostic Condition="('$(_IsExecutable)' == 'true') Or
118+
<!-- It's preferred to read IsTestingPlatformApplication in an actual MSBuild target and not in evaluation, but it's best we can do here -->
119+
<!-- NOTE: A VSTest non-MTP test project will have IsTestProject=true AND IsTestingPlatformApplication!=true -->
120+
<!-- We want to make VSTest non-MTP test project to be rid agnostic because it doesn't really produce a runnable executable -->
121+
<IsRidAgnostic Condition="('$(_IsExecutable)' == 'true' And ('$(IsTestProject)' != 'true' Or '$(IsTestingPlatformApplication)' == 'true')) Or
119122
'$(RuntimeIdentifier)' != '' Or
120123
'$(RuntimeIdentifiers)' != ''">false</IsRidAgnostic>
121124
<IsRidAgnostic Condition="'$(IsRidAgnostic)' == ''">true</IsRidAgnostic>

test/Microsoft.NET.Build.Tests/ReferenceExeTests.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,8 @@ public void MTPNonSelfContainedExecutableCannotBeReferencedBySelfContained(bool
468468
[CombinatorialData]
469469
public void ExeProjectCanReferenceTestProject(
470470
[CombinatorialValues("xunit", "mstest")] string testTemplateName,
471-
bool setSelfContainedProperty)
471+
bool setSelfContainedProperty,
472+
bool buildWithSelfContainedFromCommandLine)
472473
{
473474
var testConsoleProject = new TestProject("ConsoleApp")
474475
{
@@ -502,10 +503,21 @@ public void ExeProjectCanReferenceTestProject(
502503
.Should()
503504
.Pass();
504505

505-
new BuildCommand(Log, consoleProjectDirectory)
506-
.Execute()
507-
.Should()
508-
.Pass();
506+
if (buildWithSelfContainedFromCommandLine)
507+
{
508+
new DotnetCommand(Log, "build", "--self-contained")
509+
.WithWorkingDirectory(consoleProjectDirectory)
510+
.Execute()
511+
.Should()
512+
.Pass();
513+
}
514+
else
515+
{
516+
new BuildCommand(Log, consoleProjectDirectory)
517+
.Execute()
518+
.Should()
519+
.Pass();
520+
}
509521
}
510522

511523
[Theory]

0 commit comments

Comments
 (0)