Skip to content

Commit 2b45b90

Browse files
authored
[StaticWebAssets] Avoid generating dependent manifests if original manifest is up to date (#43709)
1 parent 0c670ff commit 2b45b90

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/StaticWebAssetsSdk/Targets/Microsoft.NET.Sdk.StaticWebAssets.targets

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,14 +628,16 @@ Copyright (c) .NET Foundation. All rights reserved.
628628
ManifestType="Build"
629629
Assets="@(StaticWebAsset)"
630630
Endpoints="@(StaticWebAssetEndpoint)"
631-
ManifestPath="$(StaticWebAssetEndpointsBuildManifestPath)">
631+
ManifestPath="$(StaticWebAssetEndpointsBuildManifestPath)"
632+
CacheFilePath="$(StaticWebAssetBuildManifestPath)">
632633
</GenerateStaticWebAssetEndpointsManifest>
633634

634635
<GenerateStaticWebAssetsDevelopmentManifest
635636
DiscoveryPatterns="@(StaticWebAssetDiscoveryPattern)"
636637
Assets="@(StaticWebAsset)"
637638
Source="$(PackageId)"
638-
ManifestPath="$(StaticWebAssetDevelopmentManifestPath)">
639+
ManifestPath="$(StaticWebAssetDevelopmentManifestPath)"
640+
CacheFilePath="$(StaticWebAssetBuildManifestPath)">
639641
</GenerateStaticWebAssetsDevelopmentManifest>
640642

641643
<ItemGroup>

src/StaticWebAssetsSdk/Tasks/GenerateStaticWebAssetEndpointsManifest.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,16 @@ public class GenerateStaticWebAssetEndpointsManifest : Task
2323
[Required]
2424
public string ManifestPath { get; set; }
2525

26+
public string CacheFilePath { get; set; }
27+
2628
public override bool Execute()
2729
{
30+
if (!string.IsNullOrEmpty(CacheFilePath) && File.Exists(ManifestPath) && File.GetLastWriteTimeUtc(ManifestPath) > File.GetLastWriteTimeUtc(CacheFilePath))
31+
{
32+
Log.LogMessage(MessageImportance.Low, "Skipping manifest generation because manifest file '{0}' is up to date.", ManifestPath);
33+
return true;
34+
}
35+
2836
try
2937
{
3038
// Get the list of the asset that need to be part of the manifest (this is similar to GenerateStaticWebAssetsDevelopmentManifest)

src/StaticWebAssetsSdk/Tasks/GenerateStaticWebAssetsDevelopmentManifest.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,17 @@ public class GenerateStaticWebAssetsDevelopmentManifest : Task
2525
[Required]
2626
public string ManifestPath { get; set; }
2727

28+
[Required]
29+
public string CacheFilePath { get; set; }
30+
2831
public override bool Execute()
2932
{
33+
if (File.Exists(ManifestPath) && File.GetLastWriteTimeUtc(ManifestPath) > File.GetLastWriteTimeUtc(CacheFilePath))
34+
{
35+
Log.LogMessage(MessageImportance.Low, "Skipping manifest generation because manifest file '{0}' is up to date.", ManifestPath);
36+
return true;
37+
}
38+
3039
try
3140
{
3241
if (Assets.Length == 0 && DiscoveryPatterns.Length == 0)

0 commit comments

Comments
 (0)