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

Regarding the AOT compilation issue of Winui3 #4971

Closed
duwenlong2 opened this issue Dec 16, 2024 · 3 comments
Closed

Regarding the AOT compilation issue of Winui3 #4971

duwenlong2 opened this issue Dec 16, 2024 · 3 comments

Comments

@duwenlong2
Copy link

Refer to the following two documents:
https://learn.microsoft.com/zh-cn/windows/apps/windows-app-sdk/stable-channel#version-16
https://learn.microsoft.com/zh-cn/dotnet/core/deploying/native-aot/?tabs=windows%2Cnet9plus#publish-native-aot-using-the-cli

Can you provide more detailed information on how to use AOT to implement WinUI3 compilation normally?

@ghost1372
Copy link
Contributor

ghost1372 commented Dec 16, 2024

1.Add

<IsAotCompatible>True</IsAotCompatible>

analyzer will warn you if you have a code which is not supported in AOT.

2.mark your classes with partial keyword
3.for p/invoke stuff use CSWin32 nuget package (or use LibraryImport instead of DllImport)
add a NativeMethods.json file with following config: (marshaling should be disabled for p/invoke stuff)

{
  "$schema": "https://aka.ms/CsWin32.schema.json",
  "allowMarshaling": false,
  "public": false
}

4.avoid using reflection.
5.use typeof(Foo) instead of Foo.GetType()

and finally
<PublishAot>True</PublishAot>

@RDMacLachlan
Copy link
Member

Hi @duwenlong2 , did Ghost's response provide you with the information you need?

@RDMacLachlan
Copy link
Member

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

No branches or pull requests

3 participants