我正在编写一个可以运行PowerShell脚本的应用程序,我想在应用程序的线程上运行它。以下代码:
Runspace runspace = RunspaceFactory.CreateRunspace(); // create Powershell runspace
runspace.ThreadOptions = PSThreadOptions.UseCurrentThread;
在Windows 7上运行并编译正常,但由于这些错误,无法在XP中编译:
'System.Management.Automation.Runspaces.Runspace' does not contain a definition for
'ThreadOptions' and no extension method 'ThreadOptions' accepting a first argument of type
'System.Management.Automation.Runspaces.Runspace' could be found (are you missing a using
directive or an assembly reference?)
The name 'PSThreadOptions' does not exist in the current context
此问题是否与powershell v1 vs v2有关?我在XP机器上安装了.NET 4(和VS 2010)。谢谢!