如何在Visual Studio Cmdlet DLL中支持不同的Powershell版本 [英] How To support different Powershell-Versions in Visual Studio Cmdlet DLL

查看:82
本文介绍了如何在Visual Studio Cmdlet DLL中支持不同的Powershell版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们公司的某些计算机上装有Powershell的较早版本,因为由于依赖性,并非所有计算机都可以接收某些更新.我在C#CmdLet中的具有Powershell 5.1的计算机上使用了nuget扩展 Microsoft.PowerShell.5.1.ReferenceAssemblies ,在具有Powershell 5.0的计算机上使用了 Microsoft.PowerShell.5.0.ReferenceAssemblies 项目,但是我不能同时使用两者.

Our company has some computers with an older version of Powershell as not all machines are allowed to receive certain updates due to dependencies. I am using the nuget-extension Microsoft.PowerShell.5.1.ReferenceAssemblies on computers with Powershell 5.1 and Microsoft.PowerShell.5.0.ReferenceAssemblies on computers with Powershell 5.0 in my C# CmdLet Project however I can not use both together.

如何在我的C#CmdLet项目中支持多个Powershell版本?

How can I support multiple Powershell versions in my C# CmdLet project?

推荐答案

使用 PowerShellStandard.Library包以创建可在多个版本甚至多个版本中运行的模块(cmdlet);即它们可以在Windows PowerShell和PowerShell [Core]上运行.

Use the PowerShellStandard.Library package to create modules (cmdlets) that run across multiple versions and even editions; i.e., they run on both Windows PowerShell and PowerShell [Core].

  • 使用版本3 创建在PowerShell版本3和更高版本上运行的cmdlet.

  • Use version 3 to create cmdlets that run on PowerShell version 3 and later.

  • 奇怪的是,最新发布的3.x软件包是2018年的 3.0.0-preview-02 -我不知道为什么.
  • Curiously, the latest 3.x package published is 3.0.0-preview-02, from 2018 - I don't know why.

使用 5.1版创建在PowerShell 5.1及更高版本上运行的cmdlet.

Use version 5.1 to create cmdlets that run on PowerShell version 5.1 and later.

有关更多信息,请参见 PowerShell标准 GitHub存储库.

See the PowerShell Standard GitHub repo for more information.

注意:

  • PowerShellStandard.Library 软件包是指用于开发在特定计算机上从PowerShell内部运行 的代码;也就是说,它需要现有的PowerShell安装.

相比之下,以下软件包允许您 捆绑 PowerShell与您的应用程序:

By contrast, the following packages allow you to bundle PowerShell with your application:

  • Microsoft.PowerShell.SDK - for building PowerShell Core applications, based on .NET Core (cross-platform).

Microsoft.PowerShell.5.ReferenceAssemblies -用于基于.NET Framework(仅Windows)构建 Windows PowerShell 应用程序

Microsoft.PowerShell.5.ReferenceAssemblies - for building Windows PowerShell applications, based on the .NET Framework (Windows-only)

这篇关于如何在Visual Studio Cmdlet DLL中支持不同的Powershell版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆