Calling C# native Winrt APIs from WebView2 in WinAppSDK

Open
#224 1 comment 0 reactions 1 assignee View on GitHub

@jennifer-nejad is already working on this.

Since Dec 6, 2023.

Assessment

This issue has not been assessed yet.

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?

Dominant language
C++
Stars
1k
Forks
521
Avg merge
13m
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from MicrosoftEdge/WebView2Samples

All issues in MicrosoftEdge/WebView2Samples

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.