diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets
index effd43977087..8475d1cda521 100644
--- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets
+++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets
@@ -71,7 +71,7 @@ Copyright (c) .NET Foundation. All rights reserved.
'$(PublishReadyToRun)' == 'true' or
'$(PublishSingleFile)' == 'true' or
'$(PublishAot)' == 'true' or
- ('$(_IsPublishing)' == 'true' and '$(PublishSelfContained)' == 'true')
+ ('$(_CommandLineDefinedSelfContained)' != 'true' and '$(_IsPublishing)' == 'true' and '$(PublishSelfContained)' == 'true')
)">true
diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets
index 384dbb1adbc0..9a6416e9c2c7 100644
--- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets
+++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets
@@ -23,7 +23,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<_IsExecutable Condition="'$(OutputType)' == 'Exe' or '$(OutputType)'=='WinExe'">true
-
+
$(_IsExecutable)
<_UsingDefaultForHasRuntimeOutput>true
@@ -36,11 +36,10 @@ Copyright (c) .NET Foundation. All rights reserved.
-
- false
- true
+
+ $(PublishSelfContained)
-
+