Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -668,14 +668,26 @@ private void LoadAssemblies(IEnumerable<string> assemblies)
/// </summary>
private static IEnumerable<PortableExecutableReference> InitDefaultRefAssemblies()
{
// netcoreapp3.0 currently comes with 148 reference assemblies (maybe more in future), so we use a capacity of '150'.
var defaultRefAssemblies = new List<PortableExecutableReference>(150);
// Define number of reference assemblies distributed with PowerShell.
// This number is accurate as of PowerShell v7.1.0-preview.1 built with .NET v5.0.100-preview.1.20155.7
const int numberOfPowershellRefAssemblies = 151;

const int capacity = numberOfPowershellRefAssemblies + 1;
var defaultRefAssemblies = new List<PortableExecutableReference>(capacity);

foreach (string file in Directory.EnumerateFiles(s_netcoreAppRefFolder, "*.dll", SearchOption.TopDirectoryOnly))
{
defaultRefAssemblies.Add(MetadataReference.CreateFromFile(file));
}

// Add System.Management.Automation.dll
defaultRefAssemblies.Add(MetadataReference.CreateFromFile(typeof(PSObject).Assembly.Location));

// We want to avoid reallocating the internal array, so we assert if the list capacity has increased.
Diagnostics.Assert(
defaultRefAssemblies.Capacity <= capacity,
$"defaultRefAssemblies was resized because of insufficient initial capacity! A capacity of {defaultRefAssemblies.Count} is required.");

return defaultRefAssemblies;
}

Expand Down