Skip to content

Analyzers for publish only functionality #14562

Closed
@vitek-karas

Description

@vitek-karas

Problem statement

For example for application trimming the goal is to make the experience predictable, as such the plan is to employ multiple tools to provide feedback to the user about the application's compatibility with trimming. The same applies to single-file publishing, AOT publishing and potentially more.

These tools will run in different stages of the SDK pipeline. Roslyn analyzers will be added to provide immediate feedback about the source code during code editing and in inner build loops. There’s already the ILLink tool which performs trimming but also analyses the app as a whole and provides feedback about the entire app. In the future there might be a "global analysis" tool somewhere in between these two.

All these tools need to be enabled only when it makes sense. If the user has no plans to ever trim the application, it would be a bad experience to show warnings about trimming.

Similarly for single-file there's an existing Roslyn analyzer and we plan to add single-file analysis into ILLink tool.

Currently the SDK defines properties which turn on the respective feature during publish. For example PublishTrimmed=true turns on trimming of the application, PublishSingleFile=true turns on publishing as single-file and so on. These properties only take effect during dotnet publish.

Ability to declare intent

To be able to keep all of the various parts of SDK in sync and provide consistent experience there needs to be a mechanism through which user declares an intent to use a publishing feature. For example a way to declare the intent to trim the application. Such mechanism must be in place across the entire SDK pipeline and not just during the publish phase.

The proposal is to repurpose the existing properties which turn on various publishing modes like PublishTrimmed or PublishSingleFile. Currently these properties only take effect during publish. The new behavior would be that these properties declare the intent to use their respective feature in the app.

Note: We've already started on this with the Roslyn single-file analyzer which is enabled only when PublishSingleFile=true. For it to work well, the property needs to be set in project file so that it's effective in builds, IDE and publish all the same. This proposal is to turn this into a general approach and design the end-to-end experience around it.

This would mean:

  • Unlike today, it would be much more common to specify these properties in the applications project file itself.
  • The values defined in the project file would become defaults for publishing, but they could be overwritten by specifying new values for a specific publish run. This is how it already works today, it's just not very common to specify these properties in the project file.
  • SDK would still need to guarantee that the properties do not directly affect results of actions like build or run. For example setting PublishSingleFile=true does not make the SDK to produce a single-file executable in dotnet build. This also is already the case today.
  • It is expected that some behavior will change even for build and run. For example PublishTrimmed=true would disable startup hooks in the application by default, for all configurations, including dotnet build. This is to make the experience consistent and in line with the goal that for example the action of trimming the application doesn't change its behavior. (As oppose to making the application compatible with trimming may change its behavior. Such a change can mean a direct code change or configuration change, like in this example disabling a feature switch.).
    See Default values for feature switches in trimmed console apps #14475 for a proposal on changing default feature switch values when trimming is enabled.
  • Various analysis tools would rely on these properties to enable/disable specific analysis for a given feature (trimming, single file, …).
  • Current VS UI has these properties in the publishing workflow only, they would need to be promoted to project-wide workflow, but also stay in the publishing workflow as overrides.
  • There's a downside in which the properties are called "Publish…" but now they would have noticeable effect outside of publish phase.

An example of declaring the intent to trim the app:

    <PropertyGroup>
        <PublishTrimmed>true</PublishTrimmed>
    </PropertyGroup>

Alternative solutions

  • Introduce a new property which would only declare the intent to eventually use trimming (or single-file, …), but leave the existing property to define the actual action of performing the trimming (or bundling to single-file, …). Such property would be harder to discover and less likely for users to use correctly.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions