Skip to content

Commit

Permalink
Fix incorrect apphost being used when publishing for self-contained s…
Browse files Browse the repository at this point in the history
…ingle-file with `NoBuild=true` (#45159)
  • Loading branch information
marcpopMSFT authored Dec 10, 2024
2 parents 74fa48e + d6df289 commit c989a6e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -791,9 +791,9 @@ Copyright (c) .NET Foundation. All rights reserved.

<!--
============================================================
_GetAppHostPaths
Gets the path to apphost (restored via packages or in an apphost pack),
and computes the path for the destination apphost.
_GetAppHostCreationConfiguration
Computes the properties for configuration of apphost creation
during either build or publish
============================================================
-->
<Target Name="_GetAppHostCreationConfiguration"
Expand Down Expand Up @@ -982,7 +982,7 @@ Copyright (c) .NET Foundation. All rights reserved.
============================================================
-->
<Target Name="_ComputeNETCoreBuildOutputFiles"
DependsOnTargets="_GetAppHostPaths;_GetComHostPaths;_GetIjwHostPaths"
DependsOnTargets="_GetAppHostPaths;_GetAppHostCreationConfiguration;_GetComHostPaths;_GetIjwHostPaths"
BeforeTargets="AssignTargetPaths"
Condition="'$(ComputeNETCoreBuildOutputFiles)' == 'true'">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit c989a6e

Please sign in to comment.