繁体   English   中英

PowerShell - 如何正确嵌入 Windows Forms 项目 - Z303CB0EF9EDB9082D61BBBE5225D7.

[英]PowerShell - how to properly embed in Windows Forms project - .NET 4.7.2

我正在使用 Windows Forms 项目只是为了尝试在使用 PowerShell 脚本的应用程序中测试脚本中的一些想法。 我无法弄清楚要添加什么 Nuget package。

我已经为我的项目尝试了多个版本的 System.Management.Automation。 https://foxlearn.com/windows-forms/how-to-execute-powershell-script-in-csharp-444.html上面的文章并没有真正进入版本信息。 当我添加 Nuget package 时,我看不到运行空间或 PowerShell 对象。

我在 C# / .NET 版本 4.7.2 下使用 Winforms。 此外,您应该在 .NET 5 控制台应用程序下使用哪个库/包?

我在 C# / .NET 版本 4.7.2 下使用 Winforms

假设您想要该运行时的最新可用版本,您需要参考“PowerShell 5.1 Reference Assemblies” package

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.PowerShell.5.1.ReferenceAssemblies" version="1.0.0" targetFramework="net472" />
</packages>

As the name implies, this package is only a shallow metadata reference, and the resulting binaries will have a runtime dependency on Windows PowerShell 5.1 (default version in all currently supported versions of Windows 10).


此外,您应该在 .NET 5 控制台应用程序下使用哪个库/包?

在这种情况下,您需要选择System.Management.Automation的最新兼容版本。


If you find yourself in a situation where you have to develop shared PowerShell components for both .NET Framework >4.5 and .NET 5, you might want to take advantage of the PowerShellStandard.Library package - it's a .NET Standard package that exposes only the parts of the API 可用于 5.1(因此它适用于 .NET 框架应用程序)和 6(因此它也适用于 .NET Core / Z2DAZ5CB0EF9EDB9088)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM