我需要显示一个从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
}我得到了错误消息:
无法加载文件..。或者依赖。找不到模块。
有没有一种使用CefSharp槽Powershell的方法?
发布于 2020-07-29 15:44:03
我和你犯了同样的错误。
通过将CEF包添加到与CefSharp dll相同的文件夹中,我解决了这个问题:
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()发布于 2021-08-23 15:31:17
[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"https://stackoverflow.com/questions/58006674
复制相似问题