Proposal: Extensibility hooks in generated main
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
# 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](https://github.com/microsoft/ProjectReunion/issues/89) requires API calls before using WPF in a Framework package
[MSIX Dynamic Dependencies](https://github.com/microsoft/ProjectReunion/issues/89) supports non-packaged processes using Framework package goods by calling APIs at runtime, accomplishing what packaged apps do via `` 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 [https://github.com/microsoft/ProjectReunion/issues/89#issuecomment-701455098](https://github.com/microsoft/ProjectReunion/issues/89#issuecomment-701455098)
> 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](https://github.com/microsoft/microsoft-ui-xaml/issues/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?
Contributor guide
Assessment
This issue has not been assessed yet.