diff --git a/src/Tasks/Common/Resources/Strings.resx b/src/Tasks/Common/Resources/Strings.resx
index da6d3f383515..6c285d7ec7bd 100644
--- a/src/Tasks/Common/Resources/Strings.resx
+++ b/src/Tasks/Common/Resources/Strings.resx
@@ -381,4 +381,16 @@ The following are names of parameters or literal values and should not be transl
NETSDK1065: Cannot find app host for {0}. {0} could be an invalid runtime identifier (RID). For more information about RID, see https://aka.ms/rid-catalog.{StrBegin="NETSDK1065: "}
+
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ {StrBegin="NETSDK1066: "}
+
+
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ {StrBegin="NETSDK1067: "}
+
+
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ {StrBegin="NETSDK1068: "}
+
diff --git a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf
index 55798ad21872..b89e4f237745 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf
@@ -7,6 +7,21 @@
Je potřeba zadat alespoň jednu možnou cílovou platformu{StrBegin="NETSDK1001: "}
+
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ {StrBegin="NETSDK1066: "}
+
+
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ {StrBegin="NETSDK1067: "}
+
+
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ {StrBegin="NETSDK1068: "}
+ NETSDK1002: Project '{0}' targets '{2}'. It cannot be referenced by a project that targets '{1}'.Cílem projektu {0} je {2}. Nemůže na něj odkazovat projekt, jehož cílem je {1}.
diff --git a/src/Tasks/Common/Resources/xlf/Strings.de.xlf b/src/Tasks/Common/Resources/xlf/Strings.de.xlf
index 4fb846e584ba..344a0780b751 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.de.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.de.xlf
@@ -7,6 +7,21 @@
Geben Sie mindestens ein mögliches Zielframework an.{StrBegin="NETSDK1001: "}
+
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ {StrBegin="NETSDK1066: "}
+
+
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ {StrBegin="NETSDK1067: "}
+
+
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ {StrBegin="NETSDK1068: "}
+ NETSDK1002: Project '{0}' targets '{2}'. It cannot be referenced by a project that targets '{1}'.Das Projekt "{0}" hat das Ziel "{2}". Ein Verweis von einem Projekt mit dem Ziel "{1}" ist nicht möglich.
diff --git a/src/Tasks/Common/Resources/xlf/Strings.es.xlf b/src/Tasks/Common/Resources/xlf/Strings.es.xlf
index d0730fc0c3cc..93d5539dfe2d 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.es.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.es.xlf
@@ -7,6 +7,21 @@
Debe especificarse al menos una plataforma de destino posible.{StrBegin="NETSDK1001: "}
+
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ {StrBegin="NETSDK1066: "}
+
+
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ {StrBegin="NETSDK1067: "}
+
+
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ {StrBegin="NETSDK1068: "}
+ NETSDK1002: Project '{0}' targets '{2}'. It cannot be referenced by a project that targets '{1}'.El proyecto "{0}" tiene como destino "{2}". No se puede hacer referencia a él mediante un proyecto que tenga como destino "{1}".
diff --git a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf
index 2e7f81e9fd37..c2e762dac9f1 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf
@@ -7,6 +7,21 @@
Au moins un framework cible doit être spécifié.{StrBegin="NETSDK1001: "}
+
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ {StrBegin="NETSDK1066: "}
+
+
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ {StrBegin="NETSDK1067: "}
+
+
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ {StrBegin="NETSDK1068: "}
+ NETSDK1002: Project '{0}' targets '{2}'. It cannot be referenced by a project that targets '{1}'.Le projet '{0}' cible '{2}'. Il ne peut pas être référencé par un projet qui cible '{1}'.
diff --git a/src/Tasks/Common/Resources/xlf/Strings.it.xlf b/src/Tasks/Common/Resources/xlf/Strings.it.xlf
index 365385bcf6ca..ea567c30502c 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.it.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.it.xlf
@@ -7,6 +7,21 @@
È necessario specificare almeno un framework di destinazione possibile.{StrBegin="NETSDK1001: "}
+
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ {StrBegin="NETSDK1066: "}
+
+
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ {StrBegin="NETSDK1067: "}
+
+
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ {StrBegin="NETSDK1068: "}
+ NETSDK1002: Project '{0}' targets '{2}'. It cannot be referenced by a project that targets '{1}'.Il progetto '{0}' è destinato a '{2}'. Non può essere usato come riferimento in un progetto destinato a '{1}'.
diff --git a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf
index 4454966618d4..ed128635222f 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf
@@ -7,6 +7,21 @@
可能性のあるターゲット フレームワークを少なくとも 1 つ指定する必要があります。{StrBegin="NETSDK1001: "}
+
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ {StrBegin="NETSDK1066: "}
+
+
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ {StrBegin="NETSDK1067: "}
+
+
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ {StrBegin="NETSDK1068: "}
+ NETSDK1002: Project '{0}' targets '{2}'. It cannot be referenced by a project that targets '{1}'.プロジェクト '{0}' は、'{2}' を対象としています。'{1}' を対象とするプロジェクトは、これを参照できません。
diff --git a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf
index 8e700b768fd8..41d18a49719a 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf
@@ -7,6 +7,21 @@
가능한 대상 프레임워크를 하나 이상 지정해야 합니다.{StrBegin="NETSDK1001: "}
+
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ {StrBegin="NETSDK1066: "}
+
+
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ {StrBegin="NETSDK1067: "}
+
+
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ {StrBegin="NETSDK1068: "}
+ NETSDK1002: Project '{0}' targets '{2}'. It cannot be referenced by a project that targets '{1}'.'{0}' 프로젝트가 '{2}'을(를) 대상으로 합니다. '{1}'을(를) 대상으로 하는 프로젝트에서 참조할 수 없습니다.
diff --git a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf
index f17a85c6bf30..c8db0b739777 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf
@@ -7,6 +7,21 @@
Należy określić co najmniej jedną możliwą platformę docelową.{StrBegin="NETSDK1001: "}
+
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ {StrBegin="NETSDK1066: "}
+
+
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ {StrBegin="NETSDK1067: "}
+
+
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ {StrBegin="NETSDK1068: "}
+ NETSDK1002: Project '{0}' targets '{2}'. It cannot be referenced by a project that targets '{1}'.Projekt „{0}” ma platformę docelową „{2}”. Nie może on być przywoływany przez projekt z platformą docelową „{1}”.
diff --git a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf
index 25c480077ebb..1d88301f5caf 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf
@@ -7,6 +7,21 @@
É necessário especificar pelo menos uma estrutura de destino possível.{StrBegin="NETSDK1001: "}
+
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ {StrBegin="NETSDK1066: "}
+
+
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ {StrBegin="NETSDK1067: "}
+
+
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ {StrBegin="NETSDK1068: "}
+ NETSDK1002: Project '{0}' targets '{2}'. It cannot be referenced by a project that targets '{1}'.O projeto '{0}' tem como destino '{2}'. Ele não pode ser referenciado por um projeto que tenha '{1}' como destino.
diff --git a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf
index dadb76d91781..02a6cc05da22 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf
@@ -7,6 +7,21 @@
Необходимо указать хотя бы одну целевую платформу.{StrBegin="NETSDK1001: "}
+
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ {StrBegin="NETSDK1066: "}
+
+
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ {StrBegin="NETSDK1067: "}
+
+
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ {StrBegin="NETSDK1068: "}
+ NETSDK1002: Project '{0}' targets '{2}'. It cannot be referenced by a project that targets '{1}'.Проект "{0}" предназначен для платформы "{2}". На него не может ссылаться проект, предназначенный для платформы "{1}".
diff --git a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf
index 4e3060cc8d15..158e2cd70498 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf
@@ -7,6 +7,21 @@
En az bir olası hedef çerçeve belirtilmelidir.{StrBegin="NETSDK1001: "}
+
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ {StrBegin="NETSDK1066: "}
+
+
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ {StrBegin="NETSDK1067: "}
+
+
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ {StrBegin="NETSDK1068: "}
+ NETSDK1002: Project '{0}' targets '{2}'. It cannot be referenced by a project that targets '{1}'.'{0}' projesi, '{2}' çerçevesini hedefliyor. Bu projeye '{1}' çerçevesini hedefleyen bir proje tarafından başvurulamaz.
diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf
index 492b2d962f23..cf60c462fb6d 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf
@@ -7,6 +7,21 @@
必须指定至少一个可能的目标框架。{StrBegin="NETSDK1001: "}
+
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ {StrBegin="NETSDK1066: "}
+
+
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ {StrBegin="NETSDK1067: "}
+
+
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ {StrBegin="NETSDK1068: "}
+ NETSDK1002: Project '{0}' targets '{2}'. It cannot be referenced by a project that targets '{1}'.项目“{0}”以“{2}”为目标。它不可由面向“{1}”的项目引用。
diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf
index 31e07bdd7bec..8cee54f60e28 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf
@@ -7,6 +7,21 @@
必須指定至少一個可能的目標 Framework。{StrBegin="NETSDK1001: "}
+
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.
+ {StrBegin="NETSDK1066: "}
+
+
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
+ {StrBegin="NETSDK1067: "}
+
+
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ NETSDK1068: The framework-dependent application host requires a target framework of at least 'netcoreapp2.1'.
+ {StrBegin="NETSDK1068: "}
+ NETSDK1002: Project '{0}' targets '{2}'. It cannot be referenced by a project that targets '{1}'.專案 '{0}' 以 '{2}' 為目標。以 '{1}' 為目標的專案無法參考該專案。
diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets
index 903eaf707ddc..6558194255fd 100644
--- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets
+++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets
@@ -17,8 +17,8 @@ Copyright (c) .NET Foundation. All rights reserved.
true
<_GetChildProjectCopyToPublishDirectoryItems Condition="'$(_GetChildProjectCopyToPublishDirectoryItems)' == ''">true
-
- true
+
+ truetrue
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 120aea4a509b..6147f35b333f 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
@@ -104,18 +104,27 @@ Copyright (c) .NET Foundation. All rights reserved.
Default SelfContained based on the RuntimeIdentifier, so projects don't have to explicitly set SelfContained.
This avoids a breaking change from 1.0 behavior.
-->
-
- false
- true
+
+ true
+ true
-
-
+
+
+
+
+
+
+
+
+
+ <_TargetFrameworkVersionWithoutV>$(TargetFrameworkVersion.TrimStart('vV'))
+
+
-
-
- <_TargetFrameworkVersionWithoutV>$(TargetFrameworkVersion.TrimStart('vV'))
-
-
-
+
+ Condition="'$(SelfContained)' == 'true' and
+ ('%(NativeCopyLocalItems.FileName)%(NativeCopyLocalItems.Extension)' == '$(_DotNetHostPolicyLibraryName)' or
+ '%(NativeCopyLocalItems.FileName)%(NativeCopyLocalItems.Extension)' == '$(_DotNetHostFxrLibraryName)')" />
@@ -326,7 +327,7 @@ Copyright (c) .NET Foundation. All rights reserved.
-
+ PreserveNewestNever
@@ -394,7 +395,7 @@ Copyright (c) .NET Foundation. All rights reserved.
-
+ dotnet
@@ -403,7 +404,7 @@ Copyright (c) .NET Foundation. All rights reserved.
$(_NetCoreRunArguments)
-
+ $(TargetDir)$(AssemblyName)$(_NativeExecutableExtension)$(StartArguments)
diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAFrameworkDependentApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAFrameworkDependentApp.cs
new file mode 100644
index 000000000000..5baf310006b4
--- /dev/null
+++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAFrameworkDependentApp.cs
@@ -0,0 +1,136 @@
+// Copyright (c) .NET Foundation and contributors. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using FluentAssertions;
+using Microsoft.DotNet.Cli.Utils;
+using Microsoft.DotNet.PlatformAbstractions;
+using Microsoft.NET.Build.Tasks;
+using Microsoft.NET.TestFramework;
+using Microsoft.NET.TestFramework.Assertions;
+using Microsoft.NET.TestFramework.Commands;
+using Xunit;
+using Xunit.Abstractions;
+
+namespace Microsoft.NET.Publish.Tests
+{
+ public class GivenThatWeWantToPublishAFrameworkDependentApp : SdkTest
+ {
+ private const string TestProjectName = "HelloWorld";
+ private const string TargetFramework = "netcoreapp2.1";
+
+ public GivenThatWeWantToPublishAFrameworkDependentApp(ITestOutputHelper log) : base(log)
+ {
+ }
+
+ [Theory]
+ [InlineData(null)]
+ [InlineData("true")]
+ [InlineData("false")]
+ public void It_publishes_with_or_without_apphost(string useAppHost)
+ {
+ var runtimeIdentifier = RuntimeEnvironment.GetRuntimeIdentifier();
+ var appHostName = $"{TestProjectName}{Constants.ExeSuffix}";
+
+ var testAsset = _testAssetsManager
+ .CopyTestAsset(TestProjectName, $"It_publishes_with_or_without_apphost_{(useAppHost ?? "null")}")
+ .WithSource();
+
+ var msbuildArgs = new List()
+ {
+ "/restore",
+ $"/p:RuntimeIdentifier={runtimeIdentifier}",
+ $"/p:TestRuntimeIdentifier={runtimeIdentifier}",
+ "/p:SelfContained=false",
+ $"/p:TargetFramework={TargetFramework}"
+ };
+
+ if (useAppHost != null)
+ {
+ msbuildArgs.Add($"/p:UseAppHost={useAppHost}");
+ }
+
+ var publishCommand = new PublishCommand(Log, testAsset.TestRoot);
+ publishCommand
+ .Execute(msbuildArgs.ToArray())
+ .Should()
+ .Pass();
+
+ var publishDirectory = publishCommand.GetOutputDirectory(TargetFramework, runtimeIdentifier: runtimeIdentifier);
+
+ var expectedFiles = new List()
+ {
+ $"{TestProjectName}.dll",
+ $"{TestProjectName}.pdb",
+ $"{TestProjectName}.deps.json",
+ $"{TestProjectName}.runtimeconfig.json",
+ };
+
+ if (useAppHost != "false")
+ {
+ expectedFiles.Add(appHostName);
+ }
+
+ publishDirectory.Should().NotHaveSubDirectories();
+ publishDirectory.Should().OnlyHaveFiles(expectedFiles);
+
+ // Run the apphost if one was generated
+ if (useAppHost != "false")
+ {
+ Command.Create(Path.Combine(publishDirectory.FullName, appHostName), Enumerable.Empty())
+ .EnvironmentVariable(
+ Environment.Is64BitProcess ? "DOTNET_ROOT" : "DOTNET_ROOT(x86)",
+ Path.GetDirectoryName(TestContext.Current.ToolsetUnderTest.DotNetHostPath))
+ .CaptureStdOut()
+ .Execute()
+ .Should()
+ .Pass()
+ .And
+ .HaveStdOutContaining("Hello World!");
+ }
+ }
+
+ [Fact]
+ public void It_errors_when_using_app_host_without_rid()
+ {
+ var testAsset = _testAssetsManager
+ .CopyTestAsset(TestProjectName)
+ .WithSource();
+
+ var publishCommand = new PublishCommand(Log, testAsset.TestRoot);
+ publishCommand
+ .Execute(
+ "/p:SelfContained=false",
+ "/p:UseAppHost=true",
+ $"/p:TargetFramework={TargetFramework}")
+ .Should()
+ .Fail()
+ .And
+ .HaveStdOutContaining(Strings.CannotUseAppHostWithoutRuntimeIdentifier);
+ }
+
+ [Fact]
+ public void It_errors_when_using_app_host_with_older_target_framework()
+ {
+ var runtimeIdentifier = RuntimeEnvironment.GetRuntimeIdentifier();
+
+ var testAsset = _testAssetsManager
+ .CopyTestAsset(TestProjectName)
+ .WithSource();
+
+ var publishCommand = new PublishCommand(Log, testAsset.TestRoot);
+ publishCommand
+ .Execute(
+ "/p:SelfContained=false",
+ "/p:UseAppHost=true",
+ $"/p:RuntimeIdentifier={runtimeIdentifier}")
+ .Should()
+ .Fail()
+ .And
+ .HaveStdOutContaining(Strings.FrameworkDependentAppHostRequiresVersion21);
+ }
+ }
+}
diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASelfContainedApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASelfContainedApp.cs
new file mode 100644
index 000000000000..b38a167f3d5f
--- /dev/null
+++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASelfContainedApp.cs
@@ -0,0 +1,68 @@
+// Copyright (c) .NET Foundation and contributors. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using FluentAssertions;
+using Microsoft.DotNet.Cli.Utils;
+using Microsoft.DotNet.PlatformAbstractions;
+using Microsoft.NET.Build.Tasks;
+using Microsoft.NET.TestFramework;
+using Microsoft.NET.TestFramework.Assertions;
+using Microsoft.NET.TestFramework.Commands;
+using System;
+using System.IO;
+using System.Linq;
+using Xunit;
+using Xunit.Abstractions;
+
+namespace Microsoft.NET.Publish.Tests
+{
+ public class GivenThatWeWantToPublishASelfContainedApp : SdkTest
+ {
+ private const string TestProjectName = "HelloWorld";
+ private const string TargetFramework = "netcoreapp2.1";
+
+ public GivenThatWeWantToPublishASelfContainedApp(ITestOutputHelper log) : base(log)
+ {
+ }
+
+ [Fact]
+ public void It_errors_when_publishing_self_contained_app_without_rid()
+ {
+ var testAsset = _testAssetsManager
+ .CopyTestAsset(TestProjectName)
+ .WithSource();
+
+ var publishCommand = new PublishCommand(Log, testAsset.TestRoot);
+ publishCommand
+ .Execute(
+ "/p:SelfContained=true",
+ $"/p:TargetFramework={TargetFramework}")
+ .Should()
+ .Fail()
+ .And
+ .HaveStdOutContaining(Strings.CannotHaveSelfContainedWithoutRuntimeIdentifier);
+ }
+
+ [Fact]
+ public void It_errors_when_publishing_self_contained_without_apphost()
+ {
+ var runtimeIdentifier = RuntimeEnvironment.GetRuntimeIdentifier();
+
+ var testAsset = _testAssetsManager
+ .CopyTestAsset(TestProjectName)
+ .WithSource();
+
+ var publishCommand = new PublishCommand(Log, testAsset.TestRoot);
+ publishCommand
+ .Execute(
+ "/p:SelfContained=true",
+ "/p:UseAppHost=false",
+ $"/p:TargetFramework={TargetFramework}",
+ $"/p:RuntimeIdentifier={runtimeIdentifier}")
+ .Should()
+ .Fail()
+ .And
+ .HaveStdOutContaining(Strings.CannotUseSelfContainedWithoutAppHost);
+ }
+ }
+}
diff --git a/src/Tests/Microsoft.NET.Publish.Tests/Microsoft.NET.Publish.Tests.csproj b/src/Tests/Microsoft.NET.Publish.Tests/Microsoft.NET.Publish.Tests.csproj
index 9208b83e145b..04aa6efe0e58 100644
--- a/src/Tests/Microsoft.NET.Publish.Tests/Microsoft.NET.Publish.Tests.csproj
+++ b/src/Tests/Microsoft.NET.Publish.Tests/Microsoft.NET.Publish.Tests.csproj
@@ -33,6 +33,7 @@
+