[release/9.0.1xx] Fix incorrect apphost being used when publishing for self-contained single-file with NoBuild=true
#45400
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport of #45159 to release/9.0.1xx
/cc @marcpopMSFT @elinor-fung
Customer Impact
Reported via:
Customers using the
--no-build
option to publish a single-file self-contained application end up with broken publish output. The published app will fail to launch. This significantly impacts source-build users.This is due to a target used for determining configuration for apphost creation (which can occur in both build and publish) not getting chained when
NoBuild=true
. Publishing with--no-build
ended up using the regular apphost (instead of the single-file, self-contained one), resulting in an app that was configured to be self-contained but did not actually have the runtime as part of itself.A workaround is to either edit the app's project file to explicitly chain in a target or stop using
--no-build
.Regression
Regression from .NET 8. Logic around configuring apphost creation used to be repeated in separate places. In .NET 9, we consolidated it into one target, but missed making sure that target was pulled in when publishing with
NoBuild=true
.Testing
Manual testing with customer repro. Added automated test.
Risk
Low. The fix chains in an existing target such that it will be still be run when
NoBuild=true
(the--no-build
option).