Skip to content

[trimming] TrimMode=full in debug mode, should enable analyzers - #9320

Merged
jonathanpeppers merged 1 commit into
dotnet:mainfrom
jonathanpeppers:TrimModeFullDebug
Sep 26, 2024
Merged

jonathanpeppers merged 1 commit into
dotnet:mainfrom
jonathanpeppers:TrimModeFullDebug

Conversation

@jonathanpeppers

@jonathanpeppers jonathanpeppers commented Sep 24, 2024 •

Copy link
Copy Markdown
Member

For NativeAOT scenarios, projects would set:

<PublishAot>true</PublishAot>

For both Debug and Release, this allows you to get the same set of analyzers in both configurations. You'd want to see the same warnings for both.

For Android, the project template is currently doing:

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <TrimMode>Full</TrimMode>
</PropertyGroup>

But this would result in a different set of warnings between Debug and Release mode!

Instead, we can do:

<PropertyGroup>
    <TrimMode>Full</TrimMode>
</PropertyGroup>

And then add a new default, such as:

<EnableTrimAnalyzer Condition="'$(EnableTrimAnalyzer)' == '' and '$(TrimMode)' == 'full'">true</EnableTrimAnalyzer>

TrimMode=Full does not enable the trimmer, so other defaults in Debug should remain unchanged.

So, the new behavior is:

  • Configuration=Debug
  • PublishTrimmed=false (default, no trimmer)
  • TrimMode=Full (project template)
  • EnableTrimAnalyzer=true (new default)
  • You get the same warnings in Debug and Release mode.

I also reworded the commend in the project template slightly, to mention it enables analyzers.

Comment on lines 272 to 273
[TestCase ("SuppressTrimAnalysisWarnings=false", new string [] { "IL2055" }, true, 2)]
[TestCase ("TrimMode=full", new string [0], false)]
[TestCase ("TrimMode=full", new string [] { "IL2055" }, false, 1)]
[TestCase ("TrimMode=full", new string [] { "IL2055" }, true, 2)]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note that you will get 2x warnings in Release, one from the trimmer and one from the Roslyn analyzer. This is "by design", and we shouldn't try to hide them or anything.

@jonathanpeppers

This comment was marked as outdated.

@jonathanpeppers
jonathanpeppers marked this pull request as ready for review September 24, 2024 21:03
For AOT scenarios, projects would set:

    <PublishAot>true</PublishAot>

For both `Debug` and `Release`, this allows you to get the same set of
analyzers in both configurations. You'd want to see the same warnings
for both.

For Android, the project template is currently doing:

    <PropertyGroup Condition="'$(Configuration)' == 'Release'">
        <TrimMode>Full</TrimMode>
    </PropertyGroup>

But this would result in a *different* set of warnings between `Debug`
and `Release` mode!

Instead, we can do:

    <PropertyGroup>
        <TrimMode>Full</TrimMode>
    </PropertyGroup>

And then add a new default, such as:

    <EnableTrimAnalyzer Condition="'$(EnableTrimAnalyzer)' == '' and '$(TrimMode)' == 'full'">true</EnableTrimAnalyzer>

`TrimMode=Full` does *not* enable the trimmer, so other defaults in
`Debug` should remain unchanged.

So, the new behavior is:

    * `Configuration=Debug`
    * `PublishTrimmed=false` (default, no trimmer)
    * `TrimMode=Full` (project template)
    * `EnableTrimAnalyzer=true` (new default)
    * You get the same warnings in `Debug` and `Release` mode.

I also reworded the commend in the project template slightly, to
mention it enables analyzers.
@jonpryor

Copy link
Copy Markdown
Contributor

Draft commit message:

For AOT scenarios, projects would set:

	<PublishAot>true</PublishAot>

For both `Debug` and `Release`, this allows you to get the same set
of analyzers in both configurations.  You'd want to see the same
warnings for both.

For Android, the project template is currently doing:

	<PropertyGroup Condition="'$(Configuration)' == 'Release'">
	  <TrimMode>Full</TrimMode>
	</PropertyGroup>

but this would result in a *different* set of warnings between
`Debug` and `Release` configuration builds!

Instead, we can do:

	<PropertyGroup>
	  <TrimMode>Full</TrimMode>
	</PropertyGroup>

And then add a new default, such as:

	<EnableTrimAnalyzer
	    Condition=" '$(EnableTrimAnalyzer)' == '' and '$(TrimMode)' == 'full' "
	>true</EnableTrimAnalyzer>

`$(TrimMode)=Full` does *not* enable the trimmer, so other defaults
in the `Debug` configuration build should remain unchanged.

So, the new behavior is:

  * `$(Configuration)=Debug`
  * `$(PublishTrimmed)=false` (default, no trimmer)
  * `$(TrimMode)=Full` (project template)
  * `$(EnableTrimAnalyzer)=true` (new default)
  * You get the same set of warnings in `Debug` and `Release`
    configuration builds.

I also reworded the comment in the project template slightly, to
mention it enables analyzers.

@jonathanpeppers : one question about that commit message: you say:

So, the new behavior is:

  • $(Configuration)=Debug`

"new behavior" implies a change in behavior. The default $(Configuration) hasn't changed. Am I misinterpreting?

@jonathanpeppers

Copy link
Copy Markdown
Member Author

I think I just missed the word “for” like: For Configuration=Debug

@jonathanpeppers
jonathanpeppers merged commit 118e894 into dotnet:main Sep 26, 2024
@jonathanpeppers
jonathanpeppers deleted the TrimModeFullDebug branch September 26, 2024 13:29
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants