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

Calling C# native Winrt APIs from WebView2 in WinAppSDK #224

Open
aaradhya1 opened this issue Dec 4, 2023 · 0 comments
Open

Calling C# native Winrt APIs from WebView2 in WinAppSDK #224

aaradhya1 opened this issue Dec 4, 2023 · 0 comments
Assignees

Comments

@aaradhya1
Copy link

aaradhya1 commented Dec 4, 2023

I followed these links(https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/winrt-from-js?tabs=winui2%2Cwinrtcsharp
https://github.com/MicrosoftEdge/WebView2Samples/compare/uwp-wv2winrt-custom-csharp-winrt) and tried to create the same for WinUI3(WinAppSDK) instead of UWP.

As part of this, below steps are followed.

  1. Created a WinAppSDK winUI3 blank app(MyWinAppSDK)
  2. Created a C++ winRT(Universal Windows) component(NativeAdapter) and configured the wv2winrt tool
  3. Created a C# Winrt(UniversalWindows) library (Native Code) which has all my Native APIs

Here, NativeAdapter has a reference to NativeCode project which has C# APIs and
MyWinAppSDK project has a reference to NativeAdapter which has the following properties set
image

Finally when trying to build MyWinAppSDK project getting the below error:

NU1201 Project NativeCode is not compatible with net6.0-windows10.0.19041 (.NETCoreApp,Version=v6.0). Project NativeCode supports: uap10.0.17763 (UAP,Version=v10.0.17763)

Kindly guide me with the above issue and it would be helpful if there are any working samples for C# APIs getting called from WebView2 code in WinUI3?

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

No branches or pull requests

2 participants