从 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 Studio 2008。我在我的解决方案中从路径
引用了 System.Management.Automation
"C:\WINDOWS\assembly\GAC_MSIL\System.Management.Automation.0.0.0__31bf3856ad364e35\System.Management.Automation.dll"
但这仅支持 Powershell v2.
我从 NuGet 下载了最新的 System.Management.Automation.dll,但我的解决方案无法识别它。这有可能实现吗?
好吧,已经很多年了,自从我什至见过 Visual Studio 2008 年的人。;-}
然而,这并不是一个真正的 PowerShell 非工作代码问题(这是我们在这里帮助解决的问题),而是一个 Visual Studio 环境/操作配置问题,以便 运行 PowerShell根本。
Visual Studio 在发布时绑定到 .Net 版本,PowerShell 也是如此。
Microsoft .NET Framework Requirements
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.0.0.0__31bf3856ad364e35
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35
C:\Windows\servicing\LCU\Package_for_RollupFix~31bf3856ad364e35~amd64~~17763.134.1.4\msil_system.management.automation_31bf3856ad364e35_10.0.17763.134_none_3a18c3b5ad9702a0\f
C:\Windows\servicing\LCU\Package_for_RollupFix~31bf3856ad364e35~amd64~~17763.134.1.4\msil_system.management.automation_31bf3856ad364e35_10.0.17763.134_none_3a18c3b5ad9702a0\r
C:\Windows\servicing\LCU\Package_for_RollupFix~31bf3856ad364e35~amd64~~17763.194.1.5\msil_system.management.automation_31bf3856ad364e35_10.0.17763.134_none_3a18c3b5ad9702a0\f
C:\Windows\servicing\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_6340379543bd8a03
C:\Windows\WinSxS\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 特定的限制,你唯一的选择是独立地 shell 到 PowerShell.exe,就像你 cmd.exe,到 运行 你的 .ps1 个文件。
您是否已经看过/尝试过以下方法/细节?
PowerShell Visual Studio 2008 templates
Visual Studio 2008 project and item templates for Windows PowerShell
including Cmdlet,
Calling a PowerShell Script From Your .NET Code
An article on embedding and/or launching PowerShell scripts from a C#
program.
Use VSCmdShell to run a PowerShell script from within Visual Studio 2008
我的系统中有 Powershell 脚本,至少需要 Powershell v4。 我有 powershell v5,我可以使用 Powershell 控制台 运行 这些脚本。
但我想从 C#-Visual Studio 2008(.net 3.5) 调用这些脚本。 我被限制使用 Visual Studio 2008。我在我的解决方案中从路径
引用了 System.Management.Automation"C:\WINDOWS\assembly\GAC_MSIL\System.Management.Automation.0.0.0__31bf3856ad364e35\System.Management.Automation.dll" 但这仅支持 Powershell v2.
我从 NuGet 下载了最新的 System.Management.Automation.dll,但我的解决方案无法识别它。这有可能实现吗?
好吧,已经很多年了,自从我什至见过 Visual Studio 2008 年的人。;-}
然而,这并不是一个真正的 PowerShell 非工作代码问题(这是我们在这里帮助解决的问题),而是一个 Visual Studio 环境/操作配置问题,以便 运行 PowerShell根本。
Visual Studio 在发布时绑定到 .Net 版本,PowerShell 也是如此。
Microsoft .NET Framework Requirements
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.0.0.0__31bf3856ad364e35 C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35 C:\Windows\servicing\LCU\Package_for_RollupFix~31bf3856ad364e35~amd64~~17763.134.1.4\msil_system.management.automation_31bf3856ad364e35_10.0.17763.134_none_3a18c3b5ad9702a0\f C:\Windows\servicing\LCU\Package_for_RollupFix~31bf3856ad364e35~amd64~~17763.134.1.4\msil_system.management.automation_31bf3856ad364e35_10.0.17763.134_none_3a18c3b5ad9702a0\r C:\Windows\servicing\LCU\Package_for_RollupFix~31bf3856ad364e35~amd64~~17763.194.1.5\msil_system.management.automation_31bf3856ad364e35_10.0.17763.134_none_3a18c3b5ad9702a0\f C:\Windows\servicing\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_6340379543bd8a03 C:\Windows\WinSxS\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 特定的限制,你唯一的选择是独立地 shell 到 PowerShell.exe,就像你 cmd.exe,到 运行 你的 .ps1 个文件。
您是否已经看过/尝试过以下方法/细节?
PowerShell Visual Studio 2008 templates
Visual Studio 2008 project and item templates for Windows PowerShell including Cmdlet,
Calling a PowerShell Script From Your .NET Code
An article on embedding and/or launching PowerShell scripts from a C# program.
Use VSCmdShell to run a PowerShell script from within Visual Studio 2008