我試圖學習如何在 C# 中使用 powershell 我正在遵循本教程但是,當我運行它時,我收到此錯誤:未處理的異常。System.InvalidProgramException:公共語言運行時檢測到無效程序。在 C:\Users\ncox\source\repos\desktopAdmin365\Program.cs 中的 DesktopAdmin365.Program.Main(String[] args) 處的 System.Management.Automation.PowerShell.Create() 處:第 11 行C:\Users\ncox\source\repos\desktopAdmin365\bin\Debug\netcoreapp3.0\desktopAdmin365.exe(進程17464)退出,代碼為-532462766。我確信在包含解決方案資源管理器中的引用/依賴項時我錯過了一些東西,但我沒有運氣通過谷歌找出哪一個這是代碼using System;using System.Management.Automation;using System.Collections.ObjectModel;namespace desktopAdmin365{ class Program { static void Main(string[] args) { using (PowerShell PowerShellInstance = PowerShell.Create()) { PowerShellInstance.AddScript("param($param1) $d = get-date; $s = 'test string value'; " + "$d; $s; $param1; get-service"); } } }}
1 回答

烙印99
TA貢獻1829條經驗 獲得超13個贊
如果您查看項目中的依賴項,您可能會看到一條有關使用 .NETFramework 恢復包且可能不兼容的警告。
您的項目是.NET core,因此您可能需要安裝Powershell Core。
或者,切換到 .net 框架解決方案,它將起作用。
- 1 回答
- 0 關注
- 142 瀏覽
添加回答
舉報
0/150
提交
取消