Skip to content

Add ability to output a shim .exe + .dll for an application (for WinRT activation) #103451

@Sergio0694

Description

@Sergio0694

Overview

We're working on enabling more scenarios on modern .NET for WinRT applications (WinUI 3, UWP). One such scenario involves applications that reference one or more WinRT components, and need to both be executed (as an app), as well as act as the implementation binary for those (merged) WinRT components.

To make this clearer, consider this scenario:

When publishing your app, you need two different binaries being produced:

  • A .dll with all the code of your published project (and referenced projects, including those WinRT components)
  • A stub .exe, which simply invokes a private Main from that .dll

This is because there's multiple activation paths for your app:

  • When launched (eg. by the user, or by the OS), that .exe will be run
  • When used as a WinRT component, that .dll will be loaded directly

To make this all work, we need two features:

  • Merging and exporting all WinRT activation factories by all referenced WinRT component projects
    • We're adding support for this in WinRT here
  • A way to publish as this ".dll + stub .exe" combination

The latter is described in more detail in this .NET Native blog post:

image

We basically need to match this for modern .NET as well.

Proposal

Talking with @MichalStrehovsky about this, he suggested we might add some UseShimExe property, which would make the build produce these two components. Ideally, this would also make things work as expected when using CoreCLR, and not just NativeAOT.

Internal tracking item (MSFT only): microsoft/OS/48896901.

Alternatives

We could do this entirely from the CsWinRT side (adding some source generator to produce a new [UnmanagedCallersOnly] method to invoke the user-defined entry point, and then bundle some native host to act as stub .exe, which we could copy to the output folder). The main issues with this approach though are that we'd need to ask users to mark their applications as using a library output type, which is very confusing and counter-intuitive, and that it's not entirely clear how we'd also make this work for CoreCLR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions