我怎样才能运行的PowerShell与.NET 4运行? [英] How can I run PowerShell with the .NET 4 runtime?

查看:148
本文介绍了我怎样才能运行的PowerShell与.NET 4运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更新,管理一些.NET程序集PowerShell脚本。剧本是为建立对.NET 2集写的,但是现在(与PowerShell的运行,该框架的版本相同)需要与.NET 4集工作,以及.NET 2集。

I am updating a PowerShell script that manages some .NET assemblies. The script was written for assemblies built against .NET 2 (the same version of the framework that PowerShell runs with), but now needs to work with .NET 4 assemblies as well as .NET 2 assemblies.

由于.NET 4的支持内置运行老版本的框架的应用程序,它似乎是最简单的办法是启动的PowerShell与.NET 4中运行时,当我需要对.NET 4集运行它。

Since .NET 4 supports running applications built against older versions of the framework, it seems like the simplest solution is to launch PowerShell with the .NET 4 runtime when I need to run it against .NET 4 assemblies.

我怎么能运行的PowerShell与.NET 4运行?

How can I run PowerShell with the .NET 4 runtime?

推荐答案

PowerShell的(发动机)运行.NET 4.0下的罚款。 PowerShell的(控制台主机和 ISE )不这样做,仅仅是因为他们被编译老版本的。净。有一个注册表设置,将修改.NET框架加载系统范围,这将反过来让PowerShell来使用.NET 4.0类:

PowerShell (the engine) runs fine under .NET 4.0. PowerShell (the console host and the ISE) do not, simply because they were compiled against older versions of .NET. There's a registry setting that will change the .NET framework loaded systemwide, which will in turn allow PowerShell to use .NET 4.0 classes:

reg add hklm\software\microsoft\.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 1
reg add hklm\software\wow6432node\microsoft\.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 1

要只更新了ISE使用.NET 4.0,您可以更改配置($ PSHome的\ powershell_ise.exe.config)文件有一大块是这样的:

To update just the ISE to use .NET 4.0, you can change the configuration ($psHome\powershell_ise.exe.config) file to have a chunk like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <startup>
      <supportedRuntime version="v4.0.30319" />
    </startup>
</configuration>

您可以构建.NET 4.0应用程序调用使用PowerShell中的PowerShell的API(System.Management.Automation.PowerShell)就好了,但这些措施将有助于获取在现成的PowerShell主机到.NET 4.0下工作。

You can build .NET 4.0 applications that call PowerShell using the PowerShell API (System.Management.Automation.PowerShell) just fine, but these steps will help get the in-the-box PowerShell hosts to work under .NET 4.0.

删除,当你不需要他们的任何更多的注册表项。这些都是全机键和强行迁移所有的应用程序到.NET 4.0,使用.NET 2,甚至应用程序的.NET 3.5

这篇关于我怎样才能运行的PowerShell与.NET 4运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆