运行 Powershell 中的 CefSharp
Running CefSharp in Powershell
我需要从 Powershell 脚本显示 CefSharp(WPF 或 Winforms)Web 浏览器控件 运行。我从 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
}
我收到错误消息:
Can not load file ... or dependecy. Module
not found.
有没有办法通过 Powershell 使用 CefSharp?
我得到了和你一样的错误。
我解决了这个问题,方法是在与 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()
[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"
我需要从 Powershell 脚本显示 CefSharp(WPF 或 Winforms)Web 浏览器控件 运行。我从 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
}
我收到错误消息:
Can not load file ... or dependecy. Module not found.
有没有办法通过 Powershell 使用 CefSharp?
我得到了和你一样的错误。
我解决了这个问题,方法是在与 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()
[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"