提升powershell启动速度

技术问题

提升powershell启动速度

2025-03-05 09:08


提升powershell启动速度

                                            




$Env:PATH = [Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()
[AppDomain]::CurrentDomain.GetAssemblies() | % {
  $pt = $_.Location
  if (! $pt) {continue}
  if ($cn++) {''}
  $na = Split-Path -Leaf $pt
  Write-Host -ForegroundColor Yellow "NGENing $na"
  ngen install $pt
}

在powershell中输入以上脚本,回车,等待执行完成,再次打开powershell就非常快了
原理:
这段 PowerShell 脚本的主要目的是对当前应用程序域(AppDomain)中加载的所有程序集执行 NGEN(Native Image Generator)安装。NGEN 是一个提高 .NET 应用程序启动性能的工具,它通过预先编译(即“ngen”化)程序集的本地代码版本,减少了 JIT(Just-In-Time)编译的需要。


label :
  • 提升powershell启动速度