亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

嘗試讓 powershell 在 C#/Visual Studio 中工作

嘗試讓 powershell 在 C#/Visual Studio 中工作

PHP
米琪卡哇伊 2024-01-20 16:14:50
我試圖學習如何在 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 框架解決方案,它將起作用。


查看完整回答
反對 回復 2024-01-20
  • 1 回答
  • 0 關注
  • 142 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號