Skip to content

Commit

Permalink
Compare lazy assemblies without extension during build
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Jul 12, 2024
1 parent 3f62dd3 commit ad088c1
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ public void WriteBootJson(Stream output, string entryAssemblyName)
{
var endpointByAsset = Endpoints.ToDictionary(e => e.GetMetadata("AssetFile"));

var lazyLoadAssembliesWithoutExtension = LazyLoadedAssemblies.ToDictionary(l =>
{
var extension = Path.GetExtension(l.ItemSpec);
if (extension == ".dll" || extension == Utils.WebcilInWasmExtension)
return Path.GetFileNameWithoutExtension(l.ItemSpec);

return l.ItemSpec;
});

var remainingLazyLoadAssemblies = new List<ITaskItem>(LazyLoadedAssemblies ?? Array.Empty<ITaskItem>());
var resourceData = result.resources;

Expand All @@ -194,7 +203,7 @@ public void WriteBootJson(Stream output, string entryAssemblyName)
var resourceName = Path.GetFileName(resource.GetMetadata("OriginalItemSpec"));
var resourceRoute = Path.GetFileName(endpointByAsset[resource.ItemSpec].ItemSpec);

if (TryGetLazyLoadedAssembly(resourceName, out var lazyLoad))
if (TryGetLazyLoadedAssembly(lazyLoadAssembliesWithoutExtension, resourceName, out var lazyLoad))
{
MapFingerprintedAsset(resourceData, resourceRoute, resourceName);
Log.LogMessage(MessageImportance.Low, "Candidate '{0}' is defined as a lazy loaded assembly.", resource.ItemSpec);
Expand All @@ -220,7 +229,7 @@ public void WriteBootJson(Stream output, string entryAssemblyName)
else if (string.Equals("symbol", assetTraitValue, StringComparison.OrdinalIgnoreCase))
{
MapFingerprintedAsset(resourceData, resourceRoute, resourceName);
if (TryGetLazyLoadedAssembly($"{fileName}.dll", out _) || TryGetLazyLoadedAssembly($"{fileName}{Utils.WebcilInWasmExtension}", out _))
if (TryGetLazyLoadedAssembly(lazyLoadAssembliesWithoutExtension, fileName, out _))
{
Log.LogMessage(MessageImportance.Low, "Candidate '{0}' is defined as a lazy loaded symbols file.", resource.ItemSpec);
resourceData.lazyAssembly ??= new ResourceHashesByNameDictionary();
Expand Down Expand Up @@ -463,9 +472,13 @@ private void AddToAdditionalResources(ITaskItem resource, Dictionary<string, Add
}
}

private bool TryGetLazyLoadedAssembly(string fileName, out ITaskItem lazyLoadedAssembly)
private static bool TryGetLazyLoadedAssembly(Dictionary<string, ITaskItem> lazyLoadAssembliesNoExtension, string fileName, out ITaskItem lazyLoadedAssembly)
{
return (lazyLoadedAssembly = LazyLoadedAssemblies?.SingleOrDefault(a => a.ItemSpec == fileName)) != null;
var extension = Path.GetExtension(fileName);
if (extension == ".dll" || extension == Utils.WebcilInWasmExtension)
fileName = Path.GetFileNameWithoutExtension(fileName);

return lazyLoadAssembliesNoExtension.TryGetValue(fileName, out lazyLoadedAssembly);
}

private Version? parsedTargetFrameworkVersion;
Expand Down

0 comments on commit ad088c1

Please sign in to comment.