-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Handle duplicate Identity in SWA dictionary construction #53328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1234,7 +1234,13 @@ internal static Dictionary<string, StaticWebAsset> ToAssetDictionary(ITaskItem[] | |
| for (var i = 0; i < candidateAssets.Length; i++) | ||
| { | ||
| var candidateAsset = FromTaskItem(candidateAssets[i], validate); | ||
| dictionary.Add(candidateAsset.Identity, candidateAsset); | ||
| // Multiple projects may reference the same physical file (e.g. NuGet cache assets | ||
| // shared across WASM clients). Since Identity is the FullPath, same Identity means | ||
| // same file on disk — keeping the first occurrence is correct. | ||
| if (!dictionary.ContainsKey(candidateAsset.Identity)) | ||
| { | ||
| dictionary.Add(candidateAsset.Identity, candidateAsset); | ||
| } | ||
|
Comment on lines
+1237
to
+1243
|
||
| } | ||
|
|
||
| return dictionary; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,8 +64,17 @@ public override bool Execute() | |
|
|
||
| // Get the list of the asset that need to be part of the manifest (this is similar to GenerateStaticWebAssetsDevelopmentManifest) | ||
| var assets = StaticWebAsset.FromTaskItemGroup(Assets); | ||
| var manifestAssets = ComputeManifestAssets(assets, ManifestType) | ||
| .ToDictionary(a => a.ResolvedAsset.Identity, a => a, OSPath.PathComparer); | ||
| // Build dictionary handling duplicate Identities from multiple projects | ||
| // referencing the same physical file (e.g. NuGet cache assets shared across WASM clients). | ||
| var manifestAssetsList = ComputeManifestAssets(assets, ManifestType); | ||
| var manifestAssets = new Dictionary<string, TargetPathAssetPair>(OSPath.PathComparer); | ||
| foreach (var a in manifestAssetsList) | ||
| { | ||
| if (!manifestAssets.ContainsKey(a.ResolvedAsset.Identity)) | ||
| { | ||
| manifestAssets.Add(a.ResolvedAsset.Identity, a); | ||
| } | ||
| } | ||
|
Comment on lines
+69
to
+77
|
||
|
|
||
| // Build exclusion matcher if patterns are provided | ||
| StaticWebAssetGlobMatcher exclusionMatcher = null; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,7 +99,16 @@ private StaticWebAssetEndpoint[] FilterPublishEndpointsIfNeeded(StaticWebAsset[] | |
| // inside the manifest because its cumbersome to do it in MSBuild directly. | ||
| if (StaticWebAssetsManifest.ManifestTypes.IsPublish(ManifestType)) | ||
| { | ||
| var assetsByIdentity = assets.ToDictionary(a => a.Identity, a => a, OSPath.PathComparer); | ||
| // Build dictionary handling duplicate Identities from multiple projects | ||
| // referencing the same physical file (e.g. NuGet cache assets shared across WASM clients). | ||
| var assetsByIdentity = new Dictionary<string, StaticWebAsset>(assets.Length, OSPath.PathComparer); | ||
| foreach (var a in assets) | ||
| { | ||
| if (!assetsByIdentity.ContainsKey(a.Identity)) | ||
| { | ||
| assetsByIdentity.Add(a.Identity, a); | ||
| } | ||
| } | ||
|
Comment on lines
+104
to
+111
|
||
| var filteredEndpoints = new List<StaticWebAssetEndpoint>(); | ||
|
|
||
| foreach (var endpoint in Endpoints.Select(StaticWebAssetEndpoint.FromTaskItem)) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The duplicate-Identity guard uses ContainsKey(...) + Add(...), which performs two lookups per candidate. Prefer a single lookup with TryGetValue to keep this linear scan as cheap as possible (especially since this runs per build).