From f852e40b3c68dbfc9b18d49708af6c4a45ebd227 Mon Sep 17 00:00:00 2001 From: Francisco Gamino Date: Fri, 3 Feb 2017 15:19:05 -0800 Subject: [PATCH] Enabling crossgen for the assemblies used by Add-Type, which are Microsoft.CodeAnalysis.CSharp.dll, Microsoft.CodeAnalysis.dll, Microsoft.CodeAnalysis.VisualBasic.dll, and Microsoft.CSharp.dll. This speeds up executing Add-Type from ~3 to 0.9 seconds. (#3086) --- build.psm1 | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/build.psm1 b/build.psm1 index 8bde70b7da..a0741e0c70 100644 --- a/build.psm1 +++ b/build.psm1 @@ -2731,6 +2731,14 @@ function Start-CrossGen { } } + # Common assemblies used by Add-Type to crossgen + $commonAssembliesForAddType = @( + "Microsoft.CodeAnalysis.CSharp.dll" + "Microsoft.CodeAnalysis.dll" + "Microsoft.CodeAnalysis.VisualBasic.dll" + "Microsoft.CSharp.dll" + ) + # Common PowerShell libraries to crossgen $psCoreAssemblyList = @( "Microsoft.PowerShell.Commands.Utility.dll", @@ -2754,7 +2762,9 @@ function Start-CrossGen { ) } - foreach ($assemblyName in $psCoreAssemblyList) { + $fullAssemblyList = $commonAssembliesForAddType + $psCoreAssemblyList + + foreach ($assemblyName in $fullAssemblyList) { $assemblyPath = Join-Path $PublishPath $assemblyName Generate-CrossGenAssembly -CrossgenPath $crossGenPath -AssemblyPath $assemblyPath } @@ -2766,12 +2776,19 @@ function Start-CrossGen { # PS assemblies, but with the same IL assembly names. # Write-Verbose "PowerShell Ngen assemblies have been generated. Deploying ..." -Verbose - foreach ($assemblyName in $psCoreAssemblyList) { + foreach ($assemblyName in $fullAssemblyList) { + # Remove the IL assembly and its symbols. $assemblyPath = Join-Path $PublishPath $assemblyName $symbolsPath = [System.IO.Path]::ChangeExtension($assemblyPath, ".pdb") + Remove-Item $assemblyPath -Force -ErrorAction Stop - Remove-Item $symbolsPath -Force -ErrorAction Stop + + # No symbols are available for Microsoft.CodeAnalysis.CSharp.dll, Microsoft.CodeAnalysis.dll, + # Microsoft.CodeAnalysis.VisualBasic.dll, and Microsoft.CSharp.dll. + if ($commonAssembliesForAddType -notcontains $assemblyName) { + Remove-Item $symbolsPath -Force -ErrorAction Stop + } # Rename the corresponding ni.dll assembly to be the same as the IL assembly $niAssemblyPath = [System.IO.Path]::ChangeExtension($assemblyPath, "ni.dll")