Skip to content

[StaticWebAssets] Process endpoint definitions in parallel #43736

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

Merged
merged 5 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -228,7 +228,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<DefineStaticWebAssetEndpoints
CandidateAssets="@(_CompressionBuildStaticWebAsset)"
AssetFileDetails="@(_ResolveBuildCompressedStaticWebAssetsDetails)"
ExistingEndpoints="@(StaticWebAssetEndpoint)"
ContentTypeMappings="@(StaticWebAssetContentTypeMapping)"
>
<Output TaskParameter="Endpoints" ItemName="_CompressionBuildStaticWebAssetEndpoint" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -682,13 +682,13 @@ Copyright (c) .NET Foundation. All rights reserved.
BasePath="$(StaticWebAssetBasePath)"
AssetMergeSource="$(StaticWebAssetMergeTarget)">
<Output TaskParameter="Assets" ItemName="StaticWebAsset" />
<Output TaskParameter="Assets" ItemName="_CurrentProjectStaticWebAsset" />
<Output TaskParameter="AssetDetails" ItemName="_ResolveProjectStaticWebAssetsDetails" />
</DefineStaticWebAssets>

<DefineStaticWebAssetEndpoints
CandidateAssets="@(StaticWebAsset)"
CandidateAssets="@(_CurrentProjectStaticWebAsset)"
AssetFileDetails="@(_ResolveProjectStaticWebAssetsDetails)"
ExistingEndpoints="@(StaticWebAssetEndpoint)"
ContentTypeMappings="@(StaticWebAssetContentTypeMapping)"
>
<Output TaskParameter="Endpoints" ItemName="StaticWebAssetEndpoint" />
Expand Down
2 changes: 2 additions & 0 deletions src/StaticWebAssetsSdk/Tasks/Data/StaticWebAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using System.Diagnostics;
using System.IO;
using System.Collections.Concurrent;
using System.Globalization;
using System.Security.Cryptography;
using System.Security.Principal;
using Microsoft.Build.Framework;
Expand Down
18 changes: 18 additions & 0 deletions src/StaticWebAssetsSdk/Tasks/Data/StaticWebAssetEndpoint.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Concurrent;
using System.Diagnostics;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
Expand Down Expand Up @@ -232,6 +233,23 @@ public int CompareTo(StaticWebAssetEndpoint other)
return 0;
}

internal static ITaskItem[] ToTaskItems(ConcurrentBag<StaticWebAssetEndpoint> endpoints)
{
if (endpoints == null || endpoints.IsEmpty)
{
return [];
}

var endpointItems = new ITaskItem[endpoints.Count];
var i = 0;
foreach (var endpoint in endpoints)
{
endpointItems[i++] = endpoint.ToTaskItem();
}

return endpointItems;
}

private class RouteAndAssetEqualityComparer : IEqualityComparer<StaticWebAssetEndpoint>
{
public bool Equals(StaticWebAssetEndpoint x, StaticWebAssetEndpoint y)
Expand Down
111 changes: 66 additions & 45 deletions src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Globalization;
using Microsoft.Build.Framework;
using Microsoft.NET.Sdk.StaticWebAssets.Tasks;
using System.Globalization;

namespace Microsoft.AspNetCore.StaticWebAssets.Tasks
{
Expand All @@ -12,7 +12,6 @@
[Required]
public ITaskItem[] CandidateAssets { get; set; }

[Required]
public ITaskItem[] ExistingEndpoints { get; set; }

[Required]
Expand Down Expand Up @@ -40,69 +39,91 @@
}
}

var staticWebAssets = CandidateAssets.Select(StaticWebAsset.FromTaskItem).ToDictionary(a => a.Identity);
var existingEndpoints = StaticWebAssetEndpoint.FromItemGroup(ExistingEndpoints);
var existingEndpointsByAssetFile = existingEndpoints
.GroupBy(e => e.AssetFile, OSPath.PathComparer)
.ToDictionary(g => g.Key, g => new HashSet<StaticWebAssetEndpoint>(g, StaticWebAssetEndpoint.RouteAndAssetComparer));

var assetsToRemove = new List<string>();
foreach (var kvp in existingEndpointsByAssetFile)
{
var asset = kvp.Key;
var set = kvp.Value;
if (!staticWebAssets.ContainsKey(asset))
{
assetsToRemove.Remove(asset);
}
}
foreach (var asset in assetsToRemove)
{
Log.LogMessage(MessageImportance.Low, $"Removing endpoints for asset '{asset}' because it no longer exists.");
existingEndpointsByAssetFile.Remove(asset);
}

var existingEndpointsByAssetFile = CreateEndpointsByAssetFile();
var contentTypeMappings = ContentTypeMappings.Select(ContentTypeMapping.FromTaskItem).OrderByDescending(m => m.Priority).ToArray();
var contentTypeProvider = new ContentTypeProvider(contentTypeMappings);
var endpoints = new List<StaticWebAssetEndpoint>();
var endpoints = new ConcurrentBag<StaticWebAssetEndpoint>();

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: macOS (x64))

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: macOS (x64))

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TemplateEngine: macOS (x64))

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TemplateEngine: macOS (x64))

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: linux (x64))

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: linux (x64))

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: linux (arm64))

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: linux (arm64))

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build ContainerBased: linux (x64) [ubuntu2204])

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build ContainerBased: linux (x64) [ubuntu2204])

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TemplateEngine: linux (x64))

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TemplateEngine: linux (x64))

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build ContainerBased: linux (x64) [debian11Amd64])

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build ContainerBased: linux (x64) [debian11Amd64])

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build ContainerBased: linux (x64) [alpine319WithNode])

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build ContainerBased: linux (x64) [alpine319WithNode])

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build ContainerBased: linux (x64) [centosStream9])

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build ContainerBased: linux (x64) [centosStream9])

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build ContainerBased: linux (x64) [fedora39])

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build ContainerBased: linux (x64) [fedora39])

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build AoT: macOS (x64))

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build AoT: macOS (x64))

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs#L45

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs(45,33): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ConcurrentBag<>' could not be found (are you missing a using directive or an assembly reference?)

foreach (var kvp in staticWebAssets)
Parallel.For(0, CandidateAssets.Length, i =>
{
var asset = kvp.Value;

// StaticWebAssets has this behavior where the base path for an asset only gets applied if the asset comes from a
// package or a referenced project and ignored if it comes from the current project.
// When we define the endpoint, we apply the path to the asset as if it was coming from the current project.
// If the endpoint is then passed to a referencing project or packaged into a nuget package, the path will be
// adjusted at that time.
var assetEndpoints = CreateEndpoints(asset, contentTypeProvider);
var asset = StaticWebAsset.FromTaskItem(CandidateAssets[i]);
var routes = asset.ComputeRoutes().ToList();

foreach (var endpoint in assetEndpoints)
if (existingEndpointsByAssetFile != null && existingEndpointsByAssetFile.TryGetValue(asset.Identity, out var set))
{
// Check if the endpoint we are about to define already exists. This can happen during publish as assets defined
// during the build will have already defined endpoints and we only want to add new ones.
if (existingEndpointsByAssetFile.TryGetValue(asset.Identity, out var set) &&
set.TryGetValue(endpoint, out var existingEndpoint))
for (var j = routes.Count -1; j >= 0; j--)
{
Log.LogMessage(MessageImportance.Low, $"Skipping asset {asset.Identity} because an endpoint for it already exists at {existingEndpoint.Route}.");
continue;
var (label, route, values) = routes[j];
// StaticWebAssets has this behavior where the base path for an asset only gets applied if the asset comes from a
// package or a referenced project and ignored if it comes from the current project.
// When we define the endpoint, we apply the path to the asset as if it was coming from the current project.
// If the endpoint is then passed to a referencing project or packaged into a nuget package, the path will be
// adjusted at that time.
var finalRoute = asset.IsProject() || asset.IsPackage() ? StaticWebAsset.Normalize(Path.Combine(asset.BasePath, route)) : route;

// Check if the endpoint we are about to define already exists. This can happen during publish as assets defined
// during the build will have already defined endpoints and we only want to add new ones.
if (set.Contains(finalRoute))
{
Log.LogMessage(MessageImportance.Low, $"Skipping asset {asset.Identity} because an endpoint for it already exists at {route}.");
routes.RemoveAt(j);
}
}
}

foreach (var endpoint in CreateEndpoints(routes, asset, contentTypeProvider))
{
Log.LogMessage(MessageImportance.Low, $"Adding endpoint {endpoint.Route} for asset {asset.Identity}.");
endpoints.Add(endpoint);
}
}
});

Endpoints = StaticWebAssetEndpoint.ToTaskItems(endpoints);

return !Log.HasLoggedErrors;
}

private List<StaticWebAssetEndpoint> CreateEndpoints(StaticWebAsset asset, ContentTypeProvider contentTypeMappings)
private Dictionary<string, HashSet<string>> CreateEndpointsByAssetFile()
{
if (ExistingEndpoints != null && ExistingEndpoints.Length > 0)
{
Dictionary<string, HashSet<string>> existingEndpointsByAssetFile = new(OSPath.PathComparer);
var assets = new HashSet<string>(CandidateAssets.Length, OSPath.PathComparer);
foreach (var asset in CandidateAssets)
{
assets.Add(asset.ItemSpec);
}

for (int i = 0; i < ExistingEndpoints.Length; i++)
{
var endpointCandidate = ExistingEndpoints[i];
var assetFile = endpointCandidate.GetMetadata(nameof(StaticWebAssetEndpoint.AssetFile));
if (!assets.Contains(assetFile))
{
Log.LogMessage(MessageImportance.Low, $"Removing endpoints for asset '{assetFile}' because it no longer exists.");
continue;
}

if (!existingEndpointsByAssetFile.TryGetValue(assetFile, out var set))
{
set = new HashSet<string>(OSPath.PathComparer);
existingEndpointsByAssetFile[assetFile] = set;
}

// Add the route
set.Add(endpointCandidate.ItemSpec);
}

return existingEndpointsByAssetFile;
}

return null;
}

private List<StaticWebAssetEndpoint> CreateEndpoints(List<StaticWebAsset.StaticWebAssetResolvedRoute> routes, StaticWebAsset asset, ContentTypeProvider contentTypeMappings)
{
var routes = asset.ComputeRoutes();
var (length, lastModified) = ResolveDetails(asset);
var result = new List<StaticWebAssetEndpoint>();
var result = new List<StaticWebAssetEndpoint>();
foreach (var (label, route, values) in routes)
{
var (mimeType, cacheSetting) = ResolveContentType(asset, contentTypeMappings);
Expand Down
Loading