Mar*_*ark 4 c# powershell .net-framework-version .net-standard-2.0
我正在尝试创建一个 .net 标准 2.0 库,该库使用 PowerShell 类 (System.Management.Automation) 调用 PowerShell 命令和脚本。我想在 .Net Framework (4.7.2) 项目中使用这个 .Net Standard 库。
使用我已经尝试过Microsoft.PowerShell.SDK,并System.Management.Automation在.net标准项目NuGet包,但我不断收到此错误:
System.IO.FileLoadException
HResult=0x80131040
Message=Could not load file or assembly'System.Management.Automation, Version=6.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Run Code Online (Sandbox Code Playgroud)
.Net Standard 2.0 库项目中的示例代码:
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
PowerShell posh = PowerShell.Create();
posh.Runspace = runspace;
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?任何帮助表示赞赏。
如果你想以 .NET Standard 为目标,你应该参考PowerShellStandard.Librarynuget 包
PowerShell Standard 仅公开 PowerShell 5.1 (.NET Framework) 和 PowerShell Core (.NET Core) 之间重叠的 API 表面,因此无论您针对哪个版本进行编译,它都能正常工作。
推荐阅读:PowerShell 标准库:构建跨 Windows PowerShell 和 PowerShell Core 工作的单个模块
| 归档时间: |
|
| 查看次数: |
1727 次 |
| 最近记录: |