未找到 WebView2Loader.dll 是 Outlook VSTO 插件

发布于 2025-01-09 08:05:44 字数 1217 浏览 0 评论 0原文

我阅读了有关 WebView2Loader.dll - 文件未找到问题的信息,但无法解决我的情况:

A simple Outlook VSTO add-in with FormRegion, 在 FormRegion 内部,我放置了 WebView2 控件,并对其进行了初始化:

 private async void FormRegionWebView2_FormRegionShowing(object sender, System.EventArgs e)
        {
            await InitializeCoreWebView2Async(webView2Ctrl, @"C:\temp");
            webView2Ctrl.Source = new Uri("http://www.bing.com");
        }

 public async Task InitializeCoreWebView2Async(WebView2 wv, string webCacheDir)
        {
            CoreWebView2EnvironmentOptions options = null;
            CoreWebView2Environment webView2Environment = null;
           
            webView2Environment = await CoreWebView2Environment.CreateAsync(null, webCacheDir, options);

            await wv.EnsureCoreWebView2Async(webView2Environment);
        }

本机 dll 位于 bin\Debug\runtimes 文件夹中,

但我仍然在 InitializeCoreWebView2Async() 中得到 'WebView2Loader.dll': 找不到指定的模块'

这里是代码: https://github.com/MicrosoftEdge/WebView2Feedback/files/8117191/OutlookAddInWithWebView。 zip

任何帮助将不胜感激。

I read allot about the WebView2Loader.dll - file not found issue, but couldn't solve the problem in my case:

A simple Outlook VSTO add-in with FormRegion,
Inside the FormRegion I placed the WebView2 control, and initialized it:

 private async void FormRegionWebView2_FormRegionShowing(object sender, System.EventArgs e)
        {
            await InitializeCoreWebView2Async(webView2Ctrl, @"C:\temp");
            webView2Ctrl.Source = new Uri("http://www.bing.com");
        }

 public async Task InitializeCoreWebView2Async(WebView2 wv, string webCacheDir)
        {
            CoreWebView2EnvironmentOptions options = null;
            CoreWebView2Environment webView2Environment = null;
           
            webView2Environment = await CoreWebView2Environment.CreateAsync(null, webCacheDir, options);

            await wv.EnsureCoreWebView2Async(webView2Environment);
        }

The native dlls are in the bin\Debug\runtimes folders,

But I still get 'WebView2Loader.dll': The specified module could not be found' in InitializeCoreWebView2Async()

Here is the code:
https://github.com/MicrosoftEdge/WebView2Feedback/files/8117191/OutlookAddInWithWebView.zip

Any help would be very appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魔法少女 2025-01-16 08:05:44

首先,确保 WebView2 运行时已安装在系统上。您可以在 WebView2 运行时安装< MSDN 中的 /a> 部分。

WebView2Loader.dll 是一个本机且特定于体系结构的二进制文件,因此您需要包含您希望应用程序运行的该二进制文件的所有版本。例如:

  • 对于 x86,您将包含 x86 版本WebView2Loader.dll。
  • 对于使用 AnyCPU 的托管应用,您将包含 WebView2Loader.dll 的 x86、x64 和 arm64 版本。从适当的特定于体系结构的文件夹加载正确版本的 WebView2Loader.dll。

确保包含所有必需的特定于平台的程序集。在 随应用程序一起提供的文件文章。


顺便说一句,我发现了类似的问题 - 无法加载 DLL 'WebView2Loader.dll': 指定的模块可能找不到。。它与你所描述的非常接近。

First of all, make sure the WebView2 Runtime is installed on the system. You can read more about that in the WebView2 Runtime installation section in MSDN.

WebView2Loader.dll is a native and architecture-specific binary, so you need to include all flavors of this binary that you expect your app to run in. For example:

  • For x86, you would include the x86 version of WebView2Loader.dll.
  • For a managed app using AnyCPU, you would include the x86, x64, and arm64 versions of WebView2Loader.dll. The correct version of WebView2Loader.dll is loaded from the appropriate architecture-specific folder.

Make sure that you included all the required platform-specific assemblies. Read more about that in the Files to ship with the app article.


BTW I have found a similar issue - Unable to load DLL 'WebView2Loader.dll': The specified module could not be found.. It is very close to what you are describing.

┼── 2025-01-16 08:05:44

事实证明,Outlook 无法从运行时文件夹中获取 WebView2Loader.dll,
它必须位于输出目录本身中。

指定平台目标(到 x86)是不够的,DLL 仍然仅在运行时。
(目标框架是:.NET Framework 4.7.2)

仅从 nuget packages.config 迁移到 PackageReference (如下所述:https://learn.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference)
并指定平台目标
导致 dll 被复制到输出目录 (bin\Debug)。

我们必须准备两个单独的 ClickOnce 安装程序,一个用于 x86,一个用于 x64,
但现在 Outlook 找到了该 dll,并且 WebView2 在 FormRegion 内显示网页。

更新:实际上,这还不足以将 WebView2Loader.dll 添加到 ClickOnce application_files。
为此,我必须将 dll 定义为 csproj 文件中的内容:
在 Visual Studio (2022) 中,“卸载项目”,然后“编辑项目文件”以获取 xml 形式的加载项 .csproj,并添加以下内容:

  <ItemGroup>
    <Content Include="$(MSBuildThisFileDirectory)bin\$(Configuration)\runtimes\win-$(EffectivePlatform)\native\WebView2Loader.dll">
      <Link>%(Filename)%(Extension)</Link>
      <PublishState>Included</PublishState>
      <Visible>False</Visible>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      <Pack>false</Pack>
    </Content>
  </ItemGroup>

重新加载和发布后,Loader dll 位于 ClickOnce 安装程序应用程序文件中,并且该插件可以被分发。

It turns out that Outlook is not able to get the WebView2Loader.dll from inside the runtimes folders,
it has to be in the output directory itself.

Specifying the Platform target (to x86) was not enough, the dll was still in runtimes only.
(target framework is: .NET framework 4.7.2)

Only migrating from nuget packages.config to PackageReference (as described here: https://learn.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference)
and specifying the platform target
caused the dll to be copied to the output dir (bin\Debug).

We will have to prepare two separate ClickOnce installers, one for x86 and one for x64,
but now the dll is found by Outlook and WebView2 displays web pages inside FormRegion.

Update: Actually that wasn't enough for adding the WebView2Loader.dll to ClickOnce application_files too.
For that I had to define the dll as content in the csproj file:
In Visual Studio (2022) "Unload Project", then "Edit Project File" to get the .csproj of the add-in as xml, and adding the following:

  <ItemGroup>
    <Content Include="$(MSBuildThisFileDirectory)bin\$(Configuration)\runtimes\win-$(EffectivePlatform)\native\WebView2Loader.dll">
      <Link>%(Filename)%(Extension)</Link>
      <PublishState>Included</PublishState>
      <Visible>False</Visible>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      <Pack>false</Pack>
    </Content>
  </ItemGroup>

After reloading and publishing the Loader dll was in the ClickOnce installer application files and the add-in could be distributed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文