我正在更新管理一些 .NET 程序集的 PowerShell 脚本。该脚本是为针对 .NET 2(与 PowerShell 运行的框架版本相同)构建的程序集编写的,但现在需要使用 .NET 4 程序集以及 .NET 2 程序集。
由于 .NET 4 支持运行针对旧版本框架构建的应用程序,因此最简单的解决方案似乎是当我需要针对 .NET 4 程序集运行 PowerShell 时,使用 .NET 4 运行时启动 PowerShell。
如何使用 .NET 4 运行时运行 PowerShell?
我找到的最好的解决方案是在博客文章中将较新版本的 .NET 与 PowerShell 结合使用 http://tfl09.blogspot.com/2010/08/using-newer-versions-of-net-with.html。这允许 powershell.exe 与 .NET 4 程序集一起运行。
只需修改(或创建)$pshome\powershell.exe.config
使其包含以下内容:
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
附加的快速设置说明:
位置和文件在某种程度上依赖于平台;然而,它将为您提供如何使解决方案适合您的内嵌要点。
- You can find PowerShell's location on your computer by executing
cd $pshome
in the Powershell window (doesn't work from DOS prompt).
- 路径将类似于(示例)
C:\Windows\System32\WindowsPowerShell\v1.0\
- The filename to put configuration in is:
powershell.exe.config
if your PowerShell.exe
is being executed (create the config file if need be).
- If
PowerShellISE.Exe
正在运行,那么您需要创建其配套配置文件作为PowerShellISE.Exe.config
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)