MicrosoftEdge / MicrosoftEdge/WebView2Samples
Calling C# native Winrt APIs from WebView2 in WinAppSDK
@jennifer-nejad is already working on this.
Since Dec 6, 2023.
- Dominant language
- C++
- Stars
- 1k
- Forks
- 521
- Avg merge
- 13m
- Merged PRs (30d)
- 1
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.
- Created a WinAppSDK winUI3 blank app(MyWinAppSDK)
- Created a C++ winRT(Universal Windows) component(NativeAdapter) and configured the wv2winrt tool
- 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
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?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.