diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets index 6fa4bc2d0782..05731e1b9087 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets @@ -791,9 +791,9 @@ Copyright (c) .NET Foundation. All rights reserved. diff --git a/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileApp.cs b/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileApp.cs index c4b7f6395581..bcb21aeb7fec 100644 --- a/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileApp.cs +++ b/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileApp.cs @@ -551,6 +551,44 @@ public void It_does_not_rewrite_the_single_file_unnecessarily() fileWriteTimeAfterSecondRun.Should().Be(fileWriteTimeAfterFirstRun); } + [RequiresMSBuildVersionFact("16.8.0")] + public void It_uses_appropriate_host_on_selfcontained_publish_with_no_build() + { + var testProject = new TestProject() + { + Name = "SingleFileTest", + TargetFrameworks = ToolsetInfo.CurrentTargetFramework, + RuntimeIdentifier = RuntimeInformation.RuntimeIdentifier, + IsExe = true, + }; + testProject.AdditionalProperties.Add("SelfContained", "true"); + TestAsset testAsset = _testAssetsManager.CreateTestProject(testProject); + + // Build will create app using apphost + var buildCommand = new BuildCommand(testAsset); + buildCommand + .Execute() + .Should() + .Pass(); + + // Publish without build should create app using singlefilehost + var publishCommand = new PublishCommand(testAsset); + publishCommand + .Execute(PublishSingleFile, "/p:NoBuild=true") + .Should() + .Pass(); + string singleFilePath = Path.Combine( + GetPublishDirectory(publishCommand).FullName, + $"{testProject.Name}{Constants.ExeSuffix}"); + + // Make sure published app runs correctly + var command = new RunExeCommand(Log, singleFilePath); + command.Execute() + .Should() + .Pass() + .And.HaveStdOutContaining("Hello World"); + } + [RequiresMSBuildVersionFact("16.8.0")] public void It_rewrites_the_apphost_for_single_file_publish() {