Skip to content
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

Proposal: Extensibility hooks in generated main #3632

Open
DrusTheAxe opened this issue Oct 12, 2020 · 1 comment
Open

Proposal: Extensibility hooks in generated main #3632

DrusTheAxe opened this issue Oct 12, 2020 · 1 comment
Labels
API suggestion Early API idea and discussion, it is NOT ready for implementation Design Discussion Ongoing discussion about design without consensus
Milestone

Comments

@DrusTheAxe
Copy link

DrusTheAxe commented Oct 12, 2020

Proposal: Extensibility hooks in generated main

Summary

Optionally add hooks in the generated main code for developers to provide code to execute before any WPF code. Bonus points for hooks at the end of the generated main and other useful points for developers to add functionality without manually editing or otherwise hacking generated files in fragile ways.

Rationale

MSIX Dynamic Dependencies supports non-packaged processes using Framework package goods by calling APIs at runtime, accomplishing what packaged apps do via <PackageDependency> in their appxmanifest.xml. For non-packaged apps to use WPF via a Framework package the app needs to call APIs before accessing WPF.

This is currently impossible with WPF's generated main method. There's no opportunity for the developer to provide code to execute before the generated main uses WPF (not without fragile manual editing of the generated main). Per microsoft/WindowsAppSDK#89 (comment)

Developers shouldn't have to write code in their main method. Maybe this is fine for frameworks where the app author owns the main method. But in WPF and WinUI, the main method is generated by tooling.

The generated main should have extensibility hooks, e.g. the generated main has pre() and post() calls to InsertYourCodeHere? Maybe a new main-extensions.cpp is created with a new WPF project with void WpfMainPre() { /insert code here/ } and WpfMainPost() for devs to inject logic into their app's startup flow?

There may be other reasons (e.g. a crash handler).

See Proposal: Extensibility hooks in generated main #3408 for the equivalent ask of XAML.

Scope

Capability Priority
Optionally support a 'pre-Main' callout for developers to provide code before the generated main logic w/o editing generated files Must
Optionally support a 'post-Main' callout for developers to provide code after the generated main logic w/o editing generated files Should

Open Questions

Are there other desirable extension points in generated files/code?

@ryalanms ryalanms added API suggestion Early API idea and discussion, it is NOT ready for implementation Design Discussion Ongoing discussion about design without consensus labels Oct 16, 2020
@miloush
Copy link
Contributor

miloush commented Nov 2, 2020

The tooling generation of the Main method can be turned off by not using ApplicationDefinition build action (typically on App.xaml). You can create your own stable Main method, and simply call new Application().Run() in there.

@ryalanms ryalanms added this to the Future milestone Aug 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API suggestion Early API idea and discussion, it is NOT ready for implementation Design Discussion Ongoing discussion about design without consensus
Projects
None yet
Development

No branches or pull requests

3 participants