Please add Sample using CMake with WebView2 (with Nuget or alternative)
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- cmake, cpp
- Domain
- build-system, desktop
Research direction
Start with the existing WebView2 samples and the MakeLists.txt configuration described in the issue, then reproduce the Visual Studio 17 2022 Win32 generation command and the missing WebView2.h failure. Review the linked CMake and NuGet discussions before choosing the sample's package or alternative setup. Done means a CMake-generated Win32 sample builds against WebView2 with the setup documented for newcomers.
Written by the indexing model from the issue text.
Description
Trying to implement Microsoft's WebView2 is my first time attempting to use nuget with a native code C++ project (WIN32 target), and I suspect this experience is not unexpected/uncommon, as I believe nuget gets used far more with .net projects, but I note that nuget is what is recommented to use per: https://learn.microsoft.com/en-us/microsoft-edge/webview2/get-started/win32
I am generating Visual Studio solution files with CMake, and have added the following to my MakeLists.txt file:
set_property(TARGET ${PROJECT_NAME} PROPERTY VS_PACKAGE_REFERENCES "Microsoft.Web.WebView2_1.0.*;Microsoft.Windows.ImplementationLibrary_1.0.*")
I generate my solution file with:
cmake .. -G "Visual Studio 17 2022" -A Win32
The nuget packages were downloaded and the above works, except that when I open the solution and attempt to build the WebView2.h header (which should come from the nuget package) can not be found:
fatal error C1083: Cannot open include file: 'WebView2.h': No such file or directory
Microsoft endorses CMake for use with Visual Studio with C++ projects, particularly where the C++ project may also need to target other platforms or provide configuration over what is built. I think a developer would expect that they can write code to implement the Microsoft's WebView2 in a source file for the Win32 target or inside an #ifdef block that is WIN32 specific.
There is open ticket for this issue with the CMake team here: https://gitlab.kitware.com/cmake/cmake/-/issues/24103 but it sounds as though they have determined there is a nuget limitation preventing it from being made to work.
A ticket was created for the Nuget team but was rejected as being "By Design" here: https://github.com/NuGet/Home/issues/12204
A Microsoft Developer Community ticket is "Under Review" for the Nuget change described here: https://developercommunity.visualstudio.com/t/Impossible-to-maintain-CC-Nuget-packa/10195731
I that the above tickets demonstrate why the provided WebView 2 Getting Started / Samples code is insufficient for this very common use case, as it would be reasonable for a developer to expect this just to work, or for an alternative to be provided (such as to using nuget for the distribution, which has been chosen by Microsoft as the way to get the headers and library code needed to build against). And kindly ask that the team add a sample where CMake is used, as the tickets above demonstrate why this is needed and not obvious.
If this is not within the purview of WebView2Samples issues, I hope that as Microsoft also chose nuget, and is the developer for nuget and Visual Studio also some communication with those other project teams can be made to find a solution.
- 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
- 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.
More from MicrosoftEdge/WebView2Samples
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 72/100
MicrosoftEdge/WebView2Samples#5 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 10/100
MicrosoftEdge/WebView2Samples#282 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
MicrosoftEdge/WebView2Samples#277 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
MicrosoftEdge/WebView2Samples#273 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
MicrosoftEdge/WebView2Samples#268 ·
All issues in MicrosoftEdge/WebView2Samples
Similar issues
-
enhancement
Difficulty 1/5 Under an hour Newbie friendliness 88/100
QuantStack/git2cpp#187 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
mlcommons/mobile_app_open#1182 ·
-
Needs-Triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/winget-cli#6547 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·