从 .NET Core 运行 PowerShell [英] Running PowerShell from .NET Core

查看:47
本文介绍了从 .NET Core 运行 PowerShell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从 .net-core 运行 PowerShell 脚本?

Is there a way to run PowerShell scripts from .net-core ?

我正在尝试在新的 .net 核心websiteapi"中运行 PowerShell 脚本.据我所知,为了在 .net 上运行 PowerShell,我们需要添加

I'm trying to run a PowerShell script in a new .net core 'websiteapi'. From what I can tell in order to run PowerShell on .net we need to add the

System.Management.Automation 命名空间.

System.Management.Automation namespace.

这对于 .net core 是不可能的(或者我还没有找到合适的方法来添加它).有几个 NuGet 包也旨在将此 DLL 添加到项目中,但它们也不与 .net 核心兼容.有没有办法在 .net core 上做到这一点?以下是我尝试过的一些链接,但没有一个是特定于 .net 核心的:

This isn't possible for .net core ( or I haven't found the appropriate way to add it). There are a couple of NuGet packages which are also aimed at adding this DLL to project but those aren't compatible with .net core either. Is there a way to do this on .net core ? Here are some links I've tried but none of them are .net core specific:

http://www.powershellmagazine.com/2014/03/18/writing-a-powershell-module-in-c-part-1-the-basics/

在 Visual Studio 中引用 system.management.automation.dll

https://www.nuget.org/packages/System.Management.Automation/

推荐答案

官方答案是当前不支持从您自己的应用程序运行 PowerShell Core.可能最大的问题是 .Net Core 缺少 AppDomain.GetAssemblies(),这可能会在 .Net Core 1.2 中修复.

The official answer is that running PowerShell Core from your own application is currently not supported. Probably the biggest issue is that .Net Core is missing AppDomain.GetAssemblies(), which might be fixed in .Net Core 1.2.

这篇关于从 .NET Core 运行 PowerShell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆