powershell - 在 Powershell 中运行 CefSharp
问题描述
我需要显示从 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?
解决方案
我得到了和你一样的错误。
我通过在与 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()
推荐阅读
- spring-mvc - 以“选择”形式处理“空”的正确方法
- javascript - 如何使用 React Native 创建发光动画
- java - 如何在菜单项atctive中画一条线
- c# - Windows 中有没有一种方法可以为具有 DPI 意识的前景应用程序获取正确的矩形?
- html - 你在哪里放置页脚反应?
- c++ - 没有构造函数“RobotDriveSwerve::RobotDriveSwerve”的实例与参数列表匹配——参数类型是
- html - 在 HTML 中通过“href=tel:”使用括号
- javascript - 如果表单有效,如何验证表单(使用 javascript)并运行函数?
- python - 无法使用 SQL Alchemy 连接未知的 MySQL 服务器主机
- vue.js - VUE:使用分页时获取数据的问题