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

Hope to use except WinUI 3 part assemblies in UWP or Xaml islands #4972

Open
Gaoyifei1011 opened this issue Dec 16, 2024 · 3 comments
Open

Comments

@Gaoyifei1011
Copy link

Gaoyifei1011 commented Dec 16, 2024

Describe the bug

Hope to use except WinUI 3 part assemblies in UWP or Xaml islands

-----------------------------

希望能在 UWP 或 Xaml islands 中使用除 WinUI 3 之外的程序集


Currently in the new UWP with.native Aot .net 9, we can enable the UWP or Xaml islands toolchain with <UseUwp>true</UseUwp>. However, when the project wants to use some apis of the Windows App SDK, it encounters an error during compilation. At this time, if you want to reference the Windows App SDK assembly, you can only manually reference it, which is very inconvenient. I hope that an attribute can be provided in the future to solve this problem.

-----------------------------

目前在新的 UWP with .Native Aot .net 9 中,我们可以通过 <UseUwp>true</UseUwp> 来启用 UWP 或 Xaml islands 工具链。然而当项目想要使用 Windows App SDK 的一些 API 时,在编译时却遇到了错误,这时如果想要引用 Windows App SDK 程序集只能手动引用,这非常不方便,希望未来能提供一个属性以解决这一问题。

Error(错误)
Image

Manual reference(手动引用)
Image

Steps to reproduce the bug

See description

Expected behavior

See description

Screenshots

See description

NuGet package version

Windows App SDK 1.6.3: 1.6.241114003

Packaging type

Packaged (MSIX)

Windows version

Insider Build (xxxxx), Windows 11 version 22H2 (22621, 2022 Update)

IDE

Visual Studio 2022

Additional context

None

@Sergio0694
Copy link
Member

Can you set EnableUnsafeMixedMicrosoftWindowsUIXamlProjections in your .csproj file and try again? 🙂

@Gaoyifei1011
Copy link
Author

Gaoyifei1011 commented Dec 17, 2024

EnableUnsafeMixedMicrosoftWindowsUIXamlProjections

Image

Image
However, when I enabled this option, the error still occurred.

------------------------------

然而当我开启这一个选项后,仍然发生错误。


Image

My project (Xaml islands) is running afoul of some WinUI 3 apis because it uses WinUI 2.

------------------------------

我的项目(Xaml islands)由于使用了 WinUI 2,故与 WinUI 3 的部分 API 发生了冲突。

@Sergio0694
Copy link
Member

"However, when I enabled this option, the error still occurred."

Ah, right, you're on 1.6.x, there was still that error back then. I plan on fixing it for 1.7 🙂
For now, you might be able to fix it if you manage to manually remove the Microsoft.WinUI.dll. Completely untested (and not supported), but try defining a target that runs before "CheckForInvalidWinUIReferenceInMixedScenarios", and remove Microsoft.WinUI.dll from @(ReferencePath). That in theory should fix that build error that checks for that reference.

"My project (Xaml islands) is running afoul of some WinUI 3 apis because it uses WinUI 2."

That is expected, given you're referencing the projections for both. You should be able to work around that by using an alias.

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

2 participants