为了账号安全,请及时绑定邮箱和手机立即绑定

尝试让 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 关注
  • 29 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信