无法在XP上运行此C#代码

时间:2010-08-30 18:19:48

标签: c# powershell automation

我正在编写一个可以运行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)。谢谢!

1 个答案:

答案 0 :(得分:4)

来自here

“此属性是在Windows PowerShell 2.0中引入的。”