Skip to content

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

Open
@aaradhya1

Description

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?

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions