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

How to create a optional package for Windows App SDK? #3112

Closed
Osirisoo0O opened this issue Nov 3, 2022 · 7 comments
Closed

How to create a optional package for Windows App SDK? #3112

Osirisoo0O opened this issue Nov 3, 2022 · 7 comments
Labels

Comments

@Osirisoo0O
Copy link

We have some plugins in our UWP app and we want use them in new WinUI 3 app.
So anyone knows what can I do ?
Thinks!

@manodasanW manodasanW transferred this issue from microsoft/CsWinRT Nov 4, 2022
@gabbybilka
Copy link
Member

Here is some documentation related to optional packages: https://learn.microsoft.com/windows/msix/package/optional-packages-with-executable-code

@cwruss Is this supported in apps using WinAppSDK specifically?

@Osirisoo0O
Copy link
Author

For CsWinRT Component, no help.
Maybe I need a complate example.

@DrusTheAxe
Copy link
Member

DrusTheAxe commented Nov 26, 2022

There are multiple possible solutions. Caveats and tradeoffs depend on more details.

What is a 'plugins' to you? WinRT inproc object? COM? DLL with exports? A class in a .NET assembly? Non-PE files? Other tech?

Devil's in the details.

@Osirisoo0O
Copy link
Author

@DrusTheAxe Just like UWP optional package. A package just work for my application.

@DrusTheAxe
Copy link
Member

DrusTheAxe commented Nov 28, 2022

So today you have a UWP app some plugins in a main package?

And you're changing the UWP app to a WinUI3 app and want to continue using the plugins?

Or you're making a new WinUI3 app in a new main package and want the plugins to be in the package? Or you want the plugins to be separate and optionally available to users who have the new main package installed?

Do you want the plugins to be shared available to both apps?

Just trying to understand your goals. There's multiple ways you can use MSIX.

@Osirisoo0O
Copy link
Author

Yes, I want change the UWP to WinUI3 app. And I want the plugins to be separate and optionally available to users who have the new main package installed.
I know too little about WinUI3.

@DrusTheAxe
Copy link
Member

Sorry for the lag, I missed this thread.

Plugins bring 2 needs to the table:

  1. Discovery
  2. Interaction

The recommended solution for #1 is <Extension Category="windows.appExtension">. Your plugins provide your needed metadata about themselves via an appextension in their appxmanifest and you enumerate and retrieve this via AppExtensionsCatalog to .Find*(), .Open() and retrieve their data.

The recommended solution for #2 is to tell developers to implement an OOP WinRT Server, put into a Main package and declare uap15:DependencyTargettrue</>. You use the Win11 Dynamic Dependencies API to add their package to your package graph (TryCreatePackageDependency, etc) and then you use routine WinRT practices to instantiate and interact with their object.

One caveat: that AppExtension support's been around for ages (since RS5 or even earlier) but <uap15:DependencyTarget> is new as of 22H2 (aka Sun Valley 2 aka 2022 Update aka 10.0.22621.0). If you need to run on older systems then the recommended answer for #2 is to tell developers to implement a Packaged COM OOP Server and put it into a Main package. Then you use CoCreateInstance() and other routine COM practices to instantiate and interact with their object.

There are possible other techniques of course. Windows has a huge palette of technologies and options. But the above is the simplest and most effective solutions, thus the recommendation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants