【问题标题】:Running CefSharp in Powershell在 Powershell 中运行 CefSharp
【发布时间】:2019-09-19 08:19:53
【问题描述】:

我需要显示从 Powershell 脚本运行的 CefSharp(WPF 或 Winforms)Webbrowser 控件。我从 nuget 包中提取了 x84 dll,并尝试像这样添加它们:

try{
    Add-Type -Path $PSScriptRoot/CefSharp.Core.dll
    Add-Type -Path $PSScriptRoot/CefSharp.BrowserSubprocess.Core.dll
    Add-Type -Path $PSScriptRoot/CefSharp.dll
    Add-Type -Path $PSScriptRoot/CefSharp.WinForms.dll
}
catch{

$_.Exception.Message
}

我收到错误消息:

无法加载文件...或依赖。模块 未找到。

有没有办法通过Powershell使用CefSharp?

【问题讨论】:

  • 您是否尝试在 64 位进程中加载​​ x86 dll?您在此处发布之前是否搜索过您遇到的错误?
  • 我使用的是正确的位版本
  • 请包含整个错误消息,哪个调用失败了?您确认您指定的文件路径正确吗?

标签: powershell cefsharp


【解决方案1】:

我遇到了和你一样的错误。

我通过在与 CefSharp dll 相同的文件夹中添加 CEF redist 包来解决问题:

https://www.nuget.org/packages/cef.redist.x64/

https://www.nuget.org/packages/cef.redist.x86/

CEF官方信息: https://bitbucket.org/chromiumembedded/cef/src/master/

我为其他人发布我的示例代码:

[System.Reflection.Assembly]::LoadFile("$AssPath\CefSharp.Core.dll")
[System.Reflection.Assembly]::LoadFile("$AssPath\CefSharp.WinForms.dll")
[System.Reflection.Assembly]::LoadFile("$AssPath\CefSharp.dll")

Add-Type -AssemblyName System.Windows.Forms

# WinForm Setup
$mainForm = New-Object System.Windows.Forms.Form
$mainForm.Font = "Comic Sans MS,9"
$mainForm.ForeColor = [System.Drawing.Color]::White
$mainForm.BackColor = [System.Drawing.Color]::DarkSlateBlue
$mainForm.Text = "CefSharp"
$mainForm.Width = 960
$mainForm.Height = 700

[CefSharp.WinForms.ChromiumWebBrowser] $browser = New-Object CefSharp.WinForms.ChromiumWebBrowser "www.google.com"
$mainForm.Controls.Add($browser)

[void] $mainForm.ShowDialog()

【讨论】:

    【解决方案2】:

    [System.Reflection.Assembly]::LoadFile 不适用于当前的 CefSharp DDL 和 PS7。

    这是工作变体:

    Import-Module -Name "$AssPath\CefSharp.Core.dll"
    Import-Module -Name "$AssPath\CefSharp.WinForms.dll"
    Import-Module -Name "$AssPath\CefSharp.dll"
    

    【讨论】:

      猜你喜欢
      • 2021-11-24
      • 2015-08-08
      • 1970-01-01
      • 2016-07-05
      • 2018-07-16
      • 1970-01-01
      • 1970-01-01
      • 2021-05-13
      • 1970-01-01
      相关资源
      最近更新 更多