在Powershell中使用Ookii.Dialogs.WinForms.dll(InputDialog)?

问题描述 投票:0回答:1

我希望利用 Ookii.Dialogs.WinForms dll(对于 .Net Framework),它允许我扩展 PowerShell 提供的开箱即用的基本消息框。我已成功使 TaskDialog 正常工作,但目前在尝试使 InputDialog 正常工作时遇到问题。我似乎所有语法都是正确的,但是在运行时,我收到以下错误。

错误:

Exception calling "ShowDialog" with "0" argument(s): "Could not load file or assembly 'System.Resources.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot 
find the file specified."

当然,这个错误让我知道发生了什么,我什至下载并导入了引用的缺失程序集,但仍然没有成功。

Add-Type -Path "C:\System.Resources.Extensions.dll"

Ookii.Dialogs.WinForms

系统.资源.扩展

我的系统详细信息:

  • Windows 11 家庭版(版本:23H2)
  • .Net框架:4.8.09032
  • PowerShell:5.1

已安装的所有 .Net 版本:

我的代码:

# Loading all possible assemblies (Yes, I know this is overkill - but trying to find what works)
Add-Type -AssemblyName System, System.Windows.Forms, System.Drawing, PresentationCore, Presentationframework, Microsoft.VisualBasic, WindowsFormsIntegration
[System.Windows.Forms.Application]::EnableVisualStyles()

# Load Ookii.Dialogs.WinForms dll into session (.dll from Nuget Package - net462)
Add-Type -Path "C:\Ookii.Dialogs.WinForms.dll"

# Build/Show cleaner InputDialog (Not the ugly Visual Basic one)
$InputDialog = [Ookii.Dialogs.WinForms.InputDialog]::new()
$InputDialog.WindowTitle = 'Input Dialog'
$InputDialog.MainInstruction = 'This is the main instruction area.'
$InputDialog.Content = 'This is me testing the content area. Just adding more info.'
$InputDialog.Input ='Placeholder'
$InputDialog.ShowDialog()
.net powershell winforms ookii
1个回答
0
投票

好吧,经过 @jdweng 提供的关于正确的 .NET 版本以及“可以”正式运行的内容的大量挖掘和信息后。我最终获得了最新版本的 Ookii.Dialogs,它构建于.NET 4.5,当然,它就可以工作了。

希望这将有助于任何通过 PowerShell 5.1 搜索并想要严格使用此 .dll 的人。

这是我的工作输入对话框:)

© www.soinside.com 2019 - 2024. All rights reserved.