我試圖學(xué)習(xí)如何在 C# 中使用 powershell 我正在遵循本教程但是,當(dāng)我運(yùn)行它時(shí),我收到此錯(cuò)誤:未處理的異常。System.InvalidProgramException:公共語(yǔ)言運(yùn)行時(shí)檢測(cè)到無(wú)效程序。在 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(進(jìn)程17464)退出,代碼為-532462766。我確信在包含解決方案資源管理器中的引用/依賴項(xiàng)時(shí)我錯(cuò)過(guò)了一些東西,但我沒有運(yùn)氣通過(guò)谷歌找出哪一個(gè)這是代碼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貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超13個(gè)贊
如果您查看項(xiàng)目中的依賴項(xiàng),您可能會(huì)看到一條有關(guān)使用 .NETFramework 恢復(fù)包且可能不兼容的警告。
您的項(xiàng)目是.NET core,因此您可能需要安裝Powershell Core。
或者,切換到 .net 框架解決方案,它將起作用。
- 1 回答
- 0 關(guān)注
- 179 瀏覽
添加回答
舉報(bào)
0/150
提交
取消