繁体   English   中英

从Visual Studio 2008调用Powershell v4及更高版本

[英]Call powershell v4 and above from Visual Studio 2008

我的系统中有Powershell脚本,至少需要Powershell v4。 我有powershell v5,可以使用Powershell控制台运行那些脚本。

但是我想从C#-Visual Studio 2008(.net 3.5)中调用这些脚本。 我只能使用Visual Studio2008。我在解决方案中从路径引用了System.Management.Automation。

“ C:\\ WINDOWS \\ assembly \\ GAC_MSIL \\ System.Management.Automation \\ 1.0.0.0__31bf3856ad364e35 \\ System.Management.Automation.dll”但这仅支持Powershell v2。

我从NuGet下载了最新的System.Management.Automation.dll,但我的解决方案无法识别它。 这有可能实现吗?

好吧,已经好几年了,自从我什至没有看到任何使用Visual Studio 2008的人

但是,这实际上不是PowerShell无法正常工作的代码问题(这是我们在这里可以帮助您解决的问题),而是一个Visual Studio环境/操作配置(为了完全运行PowerShell)。

Visual Studio在其发行版上与PowerShell绑定到.Net版本。

Microsoft .NET Framework要求

Windows PowerShell 5.1需要完整安装Microsoft .NET Framework 4.5。 Windows 8.1和Windows Server 2012 R2默认包含Microsoft .NET Framework 4.5。

Windows PowerShell 5.0需要完整安装Microsoft .NET Framework 4.5。 Windows 8.1和Windows Server 2012 R2默认包含Microsoft .NET Framework 4.5。

Windows PowerShell 4.0需要完整安装Microsoft .NET Framework 4.5。 Windows 8.1和Windows Server 2012 R2默认包含Microsoft .NET Framework 4.5。 ...

当然,由于您说过并已经在系统上使用PowerShell v5,因此您具有所需的.Net dll,而不必下载单独执行的dll。 最后,每个System.Management.Automation.dll都位于/注册在它们自己的文件夹中。

C:\\ Windows \\ assembly \\ GAC_MSIL \\ System.Management.Automation \\ 1.0.0.0__31bf3856ad364e35 C:\\ Windows \\ Microsoft.NET \\ assembly \\ GAC_MSIL \\ System.Management.Automation \\ v4.0_3.0.0.0__31bf3856ad364e35 C:\\ Windows \\维修\\ LCU \\ Package_for_RollupFix〜31bf3856ad364e35〜amd64 ~~ 17763.134.1.4 \\ msil_system.management.automation_31bf3856ad364e35_10.0.17763.134_none_3a18c3b5ad9702a0 \\ f C:\\ Windows \\ service_l〜age_3〜Pack_fad_manage_auto._COL \\ _CUP_Pack_for_RollupFix〜31 \\ bage3_ad_e3_ad_e3_ad_e3_ad_e3.exe automation_31bf3856ad364e35_10.0.17763.134_none_3a18c3b5ad9702a0 \\ r C:\\ WINDOWS \\服务\\ LCU \\ Package_for_RollupFix〜31bf3856ad364e35〜amd64的~~ 17763.194.1.5 \\ msil_system.management.automation_31bf3856ad364e35_10.0.17763.134_none_3a18c3b5ad9702a0 \\ F c的:\\ WINDOWS \\服务\\ LCU \\ Package_for_RollupFix〜31bf3856ad364e35 〜amd64 ~~ 17763.194.1.5 \\ msil_system.management.automation_31bf3856ad364e35_10.0.17763.134_none_3a18c3b5ad9702a0 \\ r C:\\ Windows \\ WinSxS \\ msil_system.management.automation_31bf3856ad364e35_1.0.0.0_none 的SxS \\ msil_system.management.automation_31bf3856ad364e35_10.0.17763.134_none_3a18c3b5ad9702a0 C:\\ WINDOWS \\ WinSxS文件\\ msil_system.management.automation_31bf3856ad364e35_10.0.17763.134_none_3a18c3b5ad9702a0 \\ F c的:\\ WINDOWS \\ WinSxS文件\\ msil_system.management.automation_31bf3856ad364e35_10.0.17763.134_none_3a18c3b5ad9702a0 \\ r C:\\的Windows \\ WinSxS文件\\ msil_system.management.automation_31bf3856ad364e35_10.0.17763.1_none_b60c54e2801db2ff

您也不要说或不演示如何尝试注册该.dll,以便Visual Studio 2008可以看到它。 因此,这似乎是Visual Studio 2008的特定限制,并且您唯一的选择是像cmd.exe一样独立运行PowerShell.exe,以运行.ps1文件。

您是否已经看过/尝试过以下方法/细节?

Visual Studio 2008 PowerShell

PowerShell Visual Studio 2008模板

Windows PowerShell的Visual Studio 2008项目和项目模板,包括Cmdlet,

从.NET代码中调用PowerShell脚本

有关从C#程序嵌入和/或启动PowerShell脚本的文章。

使用VSCmdShell在Visual Studio 2008中运行PowerShell脚本

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM