Skip to content

Don't set UseApphost or SelfContained to true for PublishAot #33229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ Copyright (c) .NET Foundation. All rights reserved.
$([MSBuild]::VersionGreaterThanOrEquals($(_TargetFrameworkVersionWithoutV), '8.0')) and
(
'$(PublishTrimmed)' == 'true' or
'$(PublishSingleFile)' == 'true' or
'$(PublishAot)' == 'true'
'$(PublishSingleFile)' == 'true'
)">
<PublishSelfContained>true</PublishSelfContained>
</PropertyGroup>
Expand Down Expand Up @@ -173,6 +172,7 @@ Copyright (c) .NET Foundation. All rights reserved.
$([MSBuild]::VersionLessThan($(_TargetFrameworkVersionWithoutV), '8.0'))">true</SelfContained>

<SelfContained Condition="'$(SelfContained)' == ''">false</SelfContained>
<SelfContained Condition="'$(PublishAot)' == 'true' and '$(_IsPublishing)' == 'true'">false</SelfContained>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically we should set PublishSelfContained=true as the app will be self-contained and some things might change behavior based on that. But that setting is also broken :-(
I just wonder if setting it to false will break something somewhere because it will now think we're publishing an FDD app.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that we're not doing either - I couldn't find a single behavior of SelfContained=true in the SDK that looks desirable for PublishAot. I don't think FDD behaviors are desirable either but I don't see any of them getting in the way the way SelfContained is so FDD just looks like a path of least resistance. The nice side effect of setting SelfContained to false is that publish is becoming faster because we no longer copy 100 files to the bin directory that Defender needs to scan.

<_RuntimeIdentifierUsesAppHost Condition="$(RuntimeIdentifier.StartsWith('ios')) or $(RuntimeIdentifier.StartsWith('tvos')) or $(RuntimeIdentifier.StartsWith('maccatalyst')) or $(RuntimeIdentifier.StartsWith('android')) or $(RuntimeIdentifier.StartsWith('browser'))">false</_RuntimeIdentifierUsesAppHost>
<_RuntimeIdentifierUsesAppHost Condition="'$(_RuntimeIdentifierUsesAppHost)' == ''">true</_RuntimeIdentifierUsesAppHost>
<UseAppHost Condition="'$(UseAppHost)' == '' and
Expand All @@ -181,6 +181,7 @@ Copyright (c) .NET Foundation. All rights reserved.
('$(RuntimeIdentifier)' != '' and '$(_TargetFrameworkVersionWithoutV)' >= '2.1') or
'$(_TargetFrameworkVersionWithoutV)' >= '3.0')">true</UseAppHost>
<UseAppHost Condition="'$(UseAppHost)' == ''">false</UseAppHost>
<UseAppHost Condition="'$(PublishAot)' == 'true' and '$(_IsPublishing)' == 'true'">false</UseAppHost>
</PropertyGroup>

<!-- Only use the default apphost if building without a RID and without a deps file path (used by GenerateDeps.proj for CLI tools). -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,11 @@ public void PublishRuntimeIdentifierOverridesUseCurrentRuntime()
[InlineData("PublishReadyToRun", true)]
[InlineData("PublishSingleFile", true)]
[InlineData("PublishTrimmed", true)]
[InlineData("PublishAot", true)]
[InlineData("PublishReadyToRun", false)]
[InlineData("PublishSingleFile", false)]
[InlineData("PublishTrimmed", false)]
public void SomePublishPropertiesInferSelfContained(string property, bool useFrameworkDependentDefaultTargetFramework)
{
// Note: there is a bug with PublishAot I think where this test will fail for Aot if the testname is too long. Do not make it longer.
var tfm = useFrameworkDependentDefaultTargetFramework ? ToolsetInfo.CurrentTargetFramework : "net7.0"; // net 7 is the last non FDD default TFM at the time of this PR.
var testProject = new TestProject()
{
Expand Down