Skip to content

Update XamlOptionalChanges spec to include new MSBuild properties - #11206

Open
evelynwu-msft wants to merge 2 commits into
mainfrom
user/evelynwu/update-xamloptionalchanges-spec
Open

Update XamlOptionalChanges spec to include new MSBuild properties#11206
evelynwu-msft wants to merge 2 commits into
mainfrom
user/evelynwu/update-xamloptionalchanges-spec

Conversation

@evelynwu-msft

Copy link
Copy Markdown
Contributor

PR Type

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

Description

During API review of the XamlOptionalChanges spec, it was decided that MSBuild properties should be added to enable and control automatic generation of the API calls by XamlCompiler and that this should be the preferred method by which developers enable or disable optional changes. Additionally, it was decided that the behavior of DISABLE_XAML_GENERATED_MAIN should be modified so that it renames the generated main method instead of removing it entirely thereby allowing custom entry points to delegate to the default implementation if desired.

This PR updates the XamlOptionalChanges spec to reflect these decisions.

… configuring code-generated calls to the API
@evelynwu-msft
evelynwu-msft requested a review from a team as a code owner June 30, 2026 20:54
@microsoft-github-policy-service microsoft-github-policy-service Bot added the needs-triage Issue needs to be triaged by the area owners label Jun 30, 2026
Comment thread specs/XamlOptionalChanges/XamlOptionalChanges-Spec.md
Comment thread specs/XamlOptionalChanges/XamlOptionalChanges-Spec.md
Comment thread specs/XamlOptionalChanges/XamlOptionalChanges-Spec.md
@evelynwu-msft
evelynwu-msft requested a review from codendone July 2, 2026 22:53
> [Approach 1](#approach-1--msbuild-properties-recommended) remain inside that
> renamed generated body.

#### Example: WinUI 3 packaged / unpackaged app

@sundaramramaswamy sundaramramaswamy Jul 10, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since DISABLE_XAML_GENERATED_MAIN now renames rather than removes the generated entry point, would it help to show a short example of delegating to XamlGeneratedProgram.XamlGeneratedMain() here? The current sample calls Application.Start() directly, so the new rename behavior isn't demonstrated. #WontFix

Copy link
Copy Markdown
Contributor 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 this is the right place to put that. Unfortunately there is no existing documentation for DISABLE_XAML_GENERATED_MAIN (the only places where it's currently mentioned are as part of samples on how to use unrelated features) so creating that document is part of my task to ensure that this new behavior is documented on MSDN.

> C#, `wXamlGeneratedMain` in C++/WinRT) so your custom entry point can still
> delegate to it if desired. Any optional-change calls produced by
> [Approach 1](#approach-1--msbuild-properties-recommended) remain inside that
> renamed generated body.

@sundaramramaswamy sundaramramaswamy Jul 10, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you clarify the expected pattern when both approaches are combined? e.g. if a developer sets MSBuild properties and defines DISABLE_XAML_GENERATED_MAIN, does delegating to the renamed entry point pick up the MSBuild-generated calls automatically? A brief note on this would help avoid double-enabling surprises.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Any optional-change calls produced by Approach 1 remain inside that renamed generated body.

This explicitly says that the API calls are still generated and remain in the renamed entry point. Does it not logically follow that, if a developer were to call the renamed entry point from their own main(), those generated API calls would be invoked in addition to whatever the developer is doing in their main()?

@ghost1372

Copy link
Copy Markdown
Contributor

is there a particular reason the new API uses comma-separated values?

Most MSBuild list properties use semicolon-separated values (for example, NoWarn, DefineConstants, etc.), so when I tested the API today, I naturally used semicolons based on my MSBuild experience. That resulted in an error because the API expects commas.

I was just curious if there was a specific design reason for choosing commas instead of following the existing MSBuild convention.

@evelynwu-msft

Copy link
Copy Markdown
Contributor Author

Unfortunately, WinAppSDK's RuntimeCompatibilityOptions feature only supports commas as the separator in the corresponding WindowsAppSDKDisabledChanges MSBuild property and so we chose to follow that same pattern with this property for consistency.


In reply to: 5001970239

@HotCakeX

Copy link
Copy Markdown

@evelynwu-msft Hi, if we define these properties in the .csproj file, does that ensure that only the selected variant is packaged with the app, rather than both variants?

If I choose the optimized variant, I would not want the default, unoptimized version to be included as well, since that would unnecessarily increase the app's package size.

@evelynwu-msft

Copy link
Copy Markdown
Contributor Author

There is no change in binary size; these are simply run-time flags that control which branch to take in certain specific parts of the codebase.


In reply to: 5048963402

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-triage Issue needs to be triaged by the area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants