为什么Powershell 2.0安装在与Powershell 1.0相同的位置?

Sim*_*mon 10 powershell powershell-2.0 windows-7

有谁知道为什么Powershell 2.0安装在Windows 7机器上的C:\ Windows\System32\WindowsPowerShell\v1.0中?

Sta*_*ing 12

这实际上是副作用中一个有趣的故事.

Visual Studio在"添加引用"对话框中有一个固定的程序集列表.
还有其他东西需要浏览.开发人员倾向于在Windows目录中浏览此位置,其中System.Management.Automation.dll(运行大部分PowerShell的程序集都存在)这对此位置进行了绝对引用.由于PowerShell不会有并行安装选项(与.NET框架一样),因此最好的选择是允许人们通过路径和StrongName继续引用相同的程序集,就像以前一样.

如果这个故事没有这样,那么所有在PowerShell V1上编写的应用程序都必须重新发布给V2.


JPB*_*anc 7

我只是认为,在最初阶段,微软团队计划并排部署PowerShell版本,就像对.NET Framework版本所做的那样.但随着时间的推移,他们决定当时只支持一个PowerShell.

当你使用命令行的-version参数来选择版本1.0时,有一些更奇怪的东西,当$PSVersionTablePSVersion值为2.0时,var 存在.PowerShell 1.0中不存在$ PSVersionTable

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>powershell -version 1.0
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. Tous droits réservés.

PS C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC> cd \
PS C:\> $PSVersionTable

Name                           Value
----                           -----
CLRVersion                     2.0.50727.4952
BuildVersion                   6.1.7600.16385
PSVersion                      2.0
WSManStackVersion              2.0
PSCompatibleVersions           {1.0, 2.0}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.1
Run Code Online (Sandbox Code Playgroud)

如果您查看$host两个版本上都存在的var

PowerShell V2.0(vith版本1.0或2.0)

PS > $host
Name             : ConsoleHost
Version          : 2.0
InstanceId       : b6ae2582-c1f4-422a-b057-16458b387f7d
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : fr-FR
CurrentUICulture : fr-FR
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace
Run Code Online (Sandbox Code Playgroud)

PowerShell V1.0

PS > $Host
Name             : ConsoleHost
Version          : 1.0.0.0
InstanceId       : b55940f2-b3b2-4f99-b895-98aac4752369
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : fr-FR
CurrentUICulture : fr-FR
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
Run Code Online (Sandbox Code Playgroud)

我的观点是PowerShell V2.0能够运行几乎所有的PowerShell V1.0脚本.微软添加了一些变量,如果你的脚本中存在这些变量,你可能会遇到麻烦,但它是花生.

J.P