首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PowerShell 6-支持Windows库

PowerShell 6-支持Windows库
EN

Stack Overflow用户
提问于 2018-01-11 14:53:20
回答 3查看 3.5K关注 0票数 2

我了解到新的PowerShell 6/core缺乏对Windows库的支持,我使用Windows.Forms .NET类在PS5.1中开发了一些重要项目。

问题:我们计划今年夏天升级到PowerShell 6,这意味着我将失去所有的GUI功能(使用Windows.Forms开发)。

问题:,在这种情况下,为了在PS应用程序中保留GUI功能,我们应该做些什么。您是否设想过微软将为GUI支持提供任何替代方案?

提亚

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-08-16 18:33:16

我的一个问题是,您所说的“升级”到PowerShell 6是什么意思?在Windows上没有升级。您将与现有版本的PowerShell 6并行运行PowerShell 6。因此,如果您想继续运行使用GUI的旧脚本,请在PowerShell 3、4或5.1中继续这样做。如果您想开始使用PowerShell 6来编写将在所有平台上运行的脚本,那么请使用PowerShell 6。好消息是,你将继续两者兼得。(至少就目前而言)

票数 0
EN

Stack Overflow用户

发布于 2018-01-15 15:40:49

感谢所有添加了内容丰富的评论。

经过一些研究后,我发现XAML UI将在.NET内核中可用,它的支持已经添加到了通用.NET平台和Xamarin应用程序中,因此它将在PowerShell core/6中用于.NET解决方案开发。

在XAML中的开发看起来非常直接,事实上,在某些方面-比其他API更容易和更快(特别是如果您必须手动编写UI组件)。

票数 1
EN

Stack Overflow用户

发布于 2019-04-20 22:33:11

这是一种俄罗斯的方法,但您可以在非PowerShell核心兼容部分使用默认的PowerShell "powershell.exe“,而不是您的PowerShell Core脚本中的PowerShell Core "pwsh.exe”:

Test.ps1:

代码语言:javascript
复制
<# Here you start your script code with your called PowerShell/PowerShell Core: #>
$PSVersionTable
chcp.com 65001;

<# Pause the PowerShell Core code execution and run here a temporary default PowerShell session 
(Non-PowerShell Core) for the Non-PowerShell Core compatible code part: #>
powershell -NoProfile -ExecutionPolicy Bypass -Command {
$PSVersionTable
chcp.com 65001;

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing");
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms");

$objForm = New-Object System.Windows.Forms.Form;

[void] $objForm.ShowDialog();

<# Exit the temporary default Non-PowerShell Core session: #>
exit
}

<# And continue here the PowerShell Core script code #>
$PSVersionTable

这对于Visual代码和只使用系统PowerShell (当前为v5.1)和PowerShell核心(当前为: v6.1.2)的CLI执行都很好。

它不仅是最好的解决方案,也是唯一的Windows,而是安装了PowerShells的Windows系统的解决方案。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48209881

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档