Skip to content

Recommend setting publish options in project file #24740

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

Merged
merged 12 commits into from
Jul 5, 2021

Conversation

sbomer
Copy link
Member

@sbomer sbomer commented Jun 18, 2021

The PublishTrimmed option also disables trim-incompatible features, and turns on a Roslyn analyzer for trim compatibility, so it should be set in the project file to ensure these settings apply during a dotnet build.

Similarly, PublishSingleFile enables a single-file analyzer so it should also be set in the project file.

Addresses part of dotnet/linker#2085.

@sbomer sbomer requested review from adegeo and tdykstra as code owners June 18, 2021 16:59
@dotnet-bot dotnet-bot added this to the June 2021 milestone Jun 18, 2021
@sbomer sbomer changed the title Publish trimmed project Recommend setting publish options in project file Jun 18, 2021

This will trim any assemblies which have been configured for trimming. With `Microsoft.NET.Sdk` in .NET 6, this includes the any assemblies with `[AssemblyMetadata("IsTrimmable", "True")]`, which is the case for framework assemblies. In .NET 5, framework assemblies from the netcoreapp runtime pack are configured for trimming via `<IsTrimmable>` MSBuild metadata. Other SDKs may define different defaults.

Starting in .NET 6, this setting also enables the trim compatibility [Roslyn analyzer](#roslyn-analyzer), and disables [features](#trimming-framework-library-features) which are incompatible with trimming.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we update the features list to include the new ones like BuiltInComInteropSupport, EnableCppCLIHostActivation etc.?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we should document the ones that are already disabled by default when linking - we don't want to encourage people to enable the unsupported ones.

But it looks like UseNativeHttpHandler is missing from the list. @eerhardt do you think we should document that one? It looks to me like UseNativeHttpHandler=true will prevent some (but not all) references to HttpClientHandler - I'm not sure whether this feature was designed for trimming in particular.

Copy link
Member

Choose a reason for hiding this comment

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

I do find it a bit confusing that we are explicitly saying disables features [link] which are incompatible with trimming, but then the link doesn't list any features which are incompatible with trimming.

Maybe we should have 2 sections? Features that can be toggled when trimming, and features that are not compatible with trimming?

But it looks like UseNativeHttpHandler is missing from the list.

@EgorBo @akoeplinger @steveisok @marek-safar - should we be documenting UseNativeHttpHandler here? I believe it is only valid for Android and iOS apps.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Starting in .NET 6, this setting also enables the trim compatibility [Roslyn analyzer](#roslyn-analyzer), and disables [features](#trimming-framework-library-features) which are incompatible with trimming.
Starting in .NET 6, this setting also enables the trim compatibility [Roslyn analyzer](#roslyn-analyzer), and disables [features that are incompatible with trimming](#trimming-framework-library-features).

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a section for the trim-incompatible features, and also added a few more switches to the optional features section, including UseNativeHttpHandler.

@@ -153,13 +153,13 @@ For more information, see the following resources:

For more information about single-file publishing, see the [single-file bundler design document](https://github.com/dotnet/designs/blob/main/accepted/2020/single-file/design.md).

We recommend that you specify this option in a publish profile rather than on the command line. For more information, see [MSBuild](#msbuild).
We recommend that you specify this option in the project file rather than on the command line. Setting it in the project file enables a Roslyn analyzer that provides single-file compatibility warnings during `dotnet build`. For more information, see [MSBuild](#msbuild).

- **`-p:PublishTrimmed=true`**
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- **`-p:PublishTrimmed=true`**
- **`<PublishTrimmed>true</PublishTrimmed>`**

Copy link
Member

Choose a reason for hiding this comment

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

Same for PublishSingleFile above

Copy link
Member Author

@sbomer sbomer Jun 18, 2021

Choose a reason for hiding this comment

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

Unfortunately this document is talking about command-line options for the dotnet publish command. Should we maybe just remove these sections from this file? It's strange that they're documented as publish options when really they're just passed to MSBuild. And these same docs then recommend not using the command-line arg version.

Copy link
Member

Choose a reason for hiding this comment

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

Removing them seems best, although the unfortunate benefit is that if you specific PublishTrimmed on the command line then it applies to all projects, and would turn on the analyzer for all of them. I suppose we also need to recommend adding EnableTrimmingAnalyzer in every project.

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed PublishTrimmed, PublishSingleFile, and PublishReadyToRun. @tdykstra does this seem ok to you?


This will trim any assemblies which have been configured for trimming. With `Microsoft.NET.Sdk` in .NET 6, this includes the any assemblies with `[AssemblyMetadata("IsTrimmable", "True")]`, which is the case for framework assemblies. In .NET 5, framework assemblies from the netcoreapp runtime pack are configured for trimming via `<IsTrimmable>` MSBuild metadata. Other SDKs may define different defaults.

Starting in .NET 6, this setting also enables the trim compatibility [Roslyn analyzer](#roslyn-analyzer), and disables [features](#trimming-framework-library-features) which are incompatible with trimming.
Copy link
Member

Choose a reason for hiding this comment

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

I do find it a bit confusing that we are explicitly saying disables features [link] which are incompatible with trimming, but then the link doesn't list any features which are incompatible with trimming.

Maybe we should have 2 sections? Features that can be toggled when trimming, and features that are not compatible with trimming?

But it looks like UseNativeHttpHandler is missing from the list.

@EgorBo @akoeplinger @steveisok @marek-safar - should we be documenting UseNativeHttpHandler here? I believe it is only valid for Android and iOS apps.

Copy link
Contributor

@tdykstra tdykstra left a comment

Choose a reason for hiding this comment

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

LGTM, a couple suggestions


This will trim any assemblies which have been configured for trimming. With `Microsoft.NET.Sdk` in .NET 6, this includes the any assemblies with `[AssemblyMetadata("IsTrimmable", "True")]`, which is the case for framework assemblies. In .NET 5, framework assemblies from the netcoreapp runtime pack are configured for trimming via `<IsTrimmable>` MSBuild metadata. Other SDKs may define different defaults.

Starting in .NET 6, this setting also enables the trim compatibility [Roslyn analyzer](#roslyn-analyzer), and disables [features](#trimming-framework-library-features) which are incompatible with trimming.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Starting in .NET 6, this setting also enables the trim compatibility [Roslyn analyzer](#roslyn-analyzer), and disables [features](#trimming-framework-library-features) which are incompatible with trimming.
Starting in .NET 6, this setting also enables the trim compatibility [Roslyn analyzer](#roslyn-analyzer), and disables [features that are incompatible with trimming](#trimming-framework-library-features).

@BillWagner BillWagner modified the milestones: June 2021, July 2021 Jul 1, 2021
sbomer added 4 commits July 1, 2021 10:17
Also document UseNativeHttpHandler, AutoreleasePoolSupport, and MetadataUpdaterSupport
- Remove unnecessary SelfContained
- Mention project properties and command-line arguments
@sbomer sbomer requested review from agocke and eerhardt July 1, 2021 17:51
sbomer and others added 3 commits July 1, 2021 14:20
Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

Looks great. Thanks for making these changes, @sbomer!

- Remove outdated single-file description
- Avoid ambiguous "this option"
- Specify value for PublishReadyToRunShowWarning
@tdykstra tdykstra merged commit 7814398 into dotnet:main Jul 5, 2021
Youssef1313 pushed a commit to Youssef1313/docs that referenced this pull request Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants