Closed asklar closed 2 years ago
This works in a uwp cppwinrt app, but for a regular win32 app, something is not passing the webview2 winmd file to cppwinrt
The problem seems to come from the webview2 pkg.
In \packages\Microsoft.Web.WebView2.1.0.955-prerelease\build\Common.targets
, it says:
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'UAP'">
<Reference Include="$(MSBuildThisFileDirectory)..\lib\Microsoft.Web.WebView2.Core.winmd">
<Implementation>Microsoft.Web.WebView2.Core.dll</Implementation>
</Reference>
<ReferenceCopyLocalPaths Include="$(MSBuildThisFileDirectory)..\runtimes\win-$(EffectivePlatform)\native_uap\Microsoft.Web.WebView2.Core.dll" />
<SDKReference Include="Microsoft.VCLibs.Desktop, Version=14.0"/>
</ItemGroup>
However this won't be evaluated for non-UWP apps like win32 xaml islands apps.
Putting this in the xaml islands project seems to get it building:
<PropertyGroup>
<EffectivePlatform>$(Platform)</EffectivePlatform>
<EffectivePlatform Condition="'$(Platform)' == 'Win32'">x86</EffectivePlatform>
</PropertyGroup>
<ItemGroup>
<Reference Include="packages\Microsoft.Web.WebView2.1.0.955-prerelease\lib\Microsoft.Web.WebView2.Core.winmd">
<Implementation>Microsoft.Web.WebView2.Core.dll</Implementation>
</Reference>
<ReferenceCopyLocalPaths Include="packages\Microsoft.Web.WebView2.1.0.955-prerelease\runtimes\win-$(EffectivePlatform)\native_uap\Microsoft.Web.WebView2.Core.dll" />
</ItemGroup>
Thanks @asklar for identifying the issue. I've sent mail to the WebView2 nupkg owners to ask them to fix this.
Hey @asklar - I've opened this issue in the WebView2Feedback repo and will follow-up there. Thanks!
It looks like both the official 2.7 and the latest prerelease (https://www.nuget.org/packages/Microsoft.UI.Xaml/2.7.0-prerelease.210913003) no longer directly depend on WebView2 and so this no longer repros (unless you manually add a dependency on a still broken version of WebView2 package)
It looks like the latest WebView2 prerelease tries to fix the missing winmd: https://www.nuget.org/packages/Microsoft.Web.WebView2/1.0.1018-prerelease
But you have to specify <WebView2UseWinRT>true</WebView2UseWinRT>
in your project files.
@jonthysell Yes that's correct. The intent is to then have the WinUI package default to setting <WebView2UseWinRT>true</WebView2UseWinRT>
.
yes. We need to update the docs to explain this. Not sure if this should be in this repo as a note, or in the winui readme that gets created when you add the nuget package to a project, or the xaml islands docs. @jevansaks @champnic thoughts?
Now that the property is available, we should just add that property to the WinUI2 nupkg targets. Something like:
<WebView2UseWinRT Condition="'$(WebView2UseWinRT)' ==''">true</WebView2UseWinRT>
@asklar can you hack your WinUI2 targets locally and see if that would address it?
@jevansaks 'tis working. PR here https://github.com/microsoft/microsoft-ui-xaml/pull/5990 (please double check me that the packaging will convert the file the change is in into microsoft.ui.xaml.targets)
@jevansaks 'tis working. PR here #5990 (please double check me that the packaging will convert the file the change is in into microsoft.ui.xaml.targets)
Thanks! Yes the nuspec renames it:
:tada:This issue was addressed in #5990, which has now been successfully released as Microsoft.UI.Xaml v2.8.0-prerelease.220712001
.:tada:
Handy links:
:tada:This issue was addressed in #5990, which has now been successfully released as Microsoft.UI.Xaml v2.8.0
.:tada:
Handy links:
I just hit this while upgrading to 2.8 from 2.7. This issue is not fixed.
I just hit this while upgrading to 2.8 from 2.7. This issue is not fixed.
can you check in the binlog if WebView2UseWinRT
is being set to true?
Yes, it's set to true
However, the build still fails
It's easy to reproduce as well. Simply creating a new C++ console project, then installing C++/WinRT and WinUI 2.8 via NuGet, will produce the following error:
Build started...
1>------ Build started: Project: ConsoleApplication95, Configuration: Debug x64 ------
1>cppwinrt : error Type 'Microsoft.Web.WebView2.Core.CoreWebView2' could not be found
1> method: CoreWebView2
1> type: Microsoft.UI.Xaml.Controls.IWebView2
1> database: T:\Projects\ConsoleApplication95\packages\Microsoft.UI.Xaml.2.8.0\lib\uap10.0\Microsoft.UI.Xaml.winmd
1>T:\Projects\ConsoleApplication95\packages\Microsoft.Windows.CppWinRT.2.0.220608.4\build\native\Microsoft.Windows.CppWinRT.targets(741,9): error MSB3073: The command ""T:\Projects\ConsoleApplication95\packages\Microsoft.Windows.CppWinRT.2.0.220608.4\build\native\..\..\bin\"cppwinrt @"x64\Debug\ConsoleApplication95.vcxproj.cppwinrt_ref.rsp"" exited with code 1.
1>Done building project "ConsoleApplication95.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
@sylveon Which version of WebView2 nuget is being used by your app? If you use an earlier preview 2.8 WinUI version or older WebView2 version does it work, or do you get the same error?
@champnic My app does not directly use WV2, it is brought in as a transitive dependency of WinUI 2.8
If I install WinUI 2.8 from Visual Studio's package manager, it automatically installs Microsoft.Web.Webview2 version 1.0.1264.42. I cannot install an older version of the WV2 NuGet without VS also forcing me to downgrade to WinUI 2.7.2 (in which case I wouldn't need the WV2 NuGet at all).
However, upgrading WebView2 to 1.0.1305-prerelease works. Installing WinUI 2.8.0-prerelease.220601001 and older works as well, and this brings in WV2 1.0.1020.30.
I am told by WV2 and WinUI 2 docs to avoid using prerelease versions to ship production apps. Prerelease WinUI 2.8 also is missing some bug fixes, and ships itself entirely with my app, turning a 2MB app download into a ~30MB one (a 1400% increase), so prerelease versions are undesirable to ship the final production app.
Thanks @sylveon! I wasn't trying to suggest using a prerelease package long-term, but just wanted info that would help us narrow down when the issue was introduced. At this point my best guess is that there is some difference between the release and prerelease versions of the WebView2 SDKs that is causing this - I'll take a look at what the differences are.
Weird - it works if I update to 1.0.305-prerelease, build, and then downgrade to 1.0.1264.42, even after running "Clean" and deleting the build folder. Do you see the same thing @sylveon?
Weird, it even seems to reproduce across projects, so now installing WinUI 2.8 on a new project "just works"
NVM the part about cross-project, I had forgot to install cppwinrt. I can reproduce this on a brand new project.
It seems to be ordering dependent. As long as the build system evaluates WebView2 .targets file after the XAML .targets file it builds fine. I can upgrade to 1.0.305-prerelease and downgrade WITHOUT building in between, and it starts working fine.
I think I see what the problem is.
When you add a nuget package reference, VS will add imports for the package’s props and targets. Props go at the top, targets at the bottom.
Neither WinUI nor webview have a props file in the right location in the package (in build\native
), for whatever reason, only targets. The WinUI targets import a props file from a directory above.
This means that it’s possible for webview2’s targets to be imported before winui’s targets (and therefore the winui props), rendering the project unbuildable.
I think the right solution is for WinUI to move its props file to the build/native directory, and remove the weird Import: https://github.com/microsoft/microsoft-ui-xaml/blob/a43efca645ce0a01ea5565a07135d867452b581e/build/NuSpecs/MUXControls-Nuget-FrameworkPackage.targets#L11
for the time being, a workaround is to switch the order of these lines in your vcxproj:
- <Import Project="packages\Microsoft.Web.WebView2.1.0.1264.42\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('packages\Microsoft.Web.WebView2.1.0.1264.42\build\native\Microsoft.Web.WebView2.targets')" />
<Import Project="packages\Microsoft.UI.Xaml.2.8.0\build\native\Microsoft.UI.Xaml.targets" Condition="Exists('packages\Microsoft.UI.Xaml.2.8.0\build\native\Microsoft.UI.Xaml.targets')" />
+ <Import Project="packages\Microsoft.Web.WebView2.1.0.1264.42\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('packages\Microsoft.Web.WebView2.1.0.1264.42\build\native\Microsoft.Web.WebView2.targets')" />
This issue has been resolved by https://github.com/microsoft/microsoft-ui-xaml/pull/7574, and is available in the 2.8.1 release.
Correct, appears fixed in 2.8.1 now, thanks!
Describe the bug I upgraded a Win32 C++/WinRT app to WinUI 2.7.0-prerelease.210827001, now I get a cppwinrt error:
Steps to reproduce the bug Create C++/WinRT app, reference latest winui nuget, build.
Note this does not require me to use WebView2 in my project - the build error happens even before any of my code gets compiled.
Version Info
NuGet package version: Microsoft.UI.Xaml 2.7.0-prerelease.210827001 latest cppwinrt version: 2.0.210825.3 mux brought in webview2 pkg: 1.0.955-prerelease