Skip to content

Commit e2a80e8

Browse files
committed
Fix the build errors on .NET SDK 9.0.300
- System.IO.FileNotFoundException at System.IO.FileInfo.get_Length()
1 parent c35b8d7 commit e2a80e8

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Build/CustomTasks/_BS_BundleAppProjectsScopedCss.targets

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ foreach (var appProj in this.ReferencedAppProjects)
4747
// Try to find "<Project Name>.styles.css" from StaticWebAsset items
4848
var appName = appProj.GetMetadata("Filename");
4949
var stylesCssName = appName + ".styles.css";
50-
var stylesCssItem = this.Items.FirstOrDefault(item => Path.GetFileName(item.GetMetadata("OriginalItemSpec")) == stylesCssName);
50+
var stylesCssItem = this.Items.FirstOrDefault(item => Path.GetFileName(item.ItemSpec) == stylesCssName);
5151
if (stylesCssItem == null) continue;
5252
5353
// Build a new StaticAsset item of "<Project Name>.bundle.scp.css" from the "<Project Name>.styles.css"
@@ -90,30 +90,35 @@ foreach (var appProj in this.ReferencedAppProjects)
9090
bundleScpCss.SetMetadata("Fingerprint", fingerprint);
9191
9292
var fileInfo = new System.IO.FileInfo(bundleScpCssPath);
93-
bundleScpCss.SetMetadata("FileLength", fileInfo.Length.ToString());
94-
bundleScpCss.SetMetadata("LastWriteTime", fileInfo.LastWriteTimeUtc.ToString("R")); // ex."Tue, 20 May 2025 23:21:08 GMT"
93+
var fileLength = stylesCssItem.GetMetadata("FileLength");
94+
var lastWriteTime = stylesCssItem.GetMetadata("LastWriteTime");
95+
if (string.IsNullOrEmpty(fileLength)) fileLength = fileInfo.Length.ToString();
96+
if (string.IsNullOrEmpty(lastWriteTime)) lastWriteTime = fileInfo.LastWriteTimeUtc.ToString("R"); // ex."Tue, 20 May 2025 23:21:08 GMT"
97+
98+
bundleScpCss.SetMetadata("FileLength", fileLength);
99+
bundleScpCss.SetMetadata("LastWriteTime", lastWriteTime);
95100
96101
projectBundle.Add(bundleScpCss);
97102
98103
// Build a new StaticWebAssetEndpoint item
99104
100-
var resHeaderFormat = "[{{\"Name\":\"Accept-Ranges\",\"Value\":\"bytes\"}},{{\"Name\":\"Cache-Control\",\"Value\":\"{0}\"}},{{\"Name\":\"Content-Length\",\"Value\":\"{1}\"}},{{\"Name\":\"Content-Type\",\"Value\":\"text/css\"}},{{\"Name\":\"ETag\",\"Value\":\"\\u0022{2}\\u0022\"}},{{\"Name\":\"Last-Modified\",\"Value\":\"{3:R}\"}}]";
105+
var resHeaderFormat = "[{{\"Name\":\"Accept-Ranges\",\"Value\":\"bytes\"}},{{\"Name\":\"Cache-Control\",\"Value\":\"{0}\"}},{{\"Name\":\"Content-Length\",\"Value\":\"{1}\"}},{{\"Name\":\"Content-Type\",\"Value\":\"text/css\"}},{{\"Name\":\"ETag\",\"Value\":\"\\u0022{2}\\u0022\"}},{{\"Name\":\"Last-Modified\",\"Value\":\"{3}\"}}]";
101106
var encodedIntegrity = integrity.Replace("+", "\\u002B").Replace("/", "\\u002F");
102107
103108
// for "_content/<Project Name>/<Project Name>.bundle.scp.css"
104109
var bundleEndpointIdentity = string.Format("_content/{0}/{0}.bundle.scp.css", appName);
105110
var bundleEndpoint = new TaskItem(bundleEndpointIdentity);
106111
bundleEndpoint.SetMetadata("AssetFile", bundleScpCssPath);
107112
bundleEndpoint.SetMetadata("Selectors", "[]");
108-
bundleEndpoint.SetMetadata("ResponseHeaders", string.Format(resHeaderFormat, "no-cache", fileInfo.Length, integrity, fileInfo.LastWriteTimeUtc));
113+
bundleEndpoint.SetMetadata("ResponseHeaders", string.Format(resHeaderFormat, "no-cache", fileLength, integrity, lastWriteTime));
109114
bundleEndpoint.SetMetadata("EndpointProperties", string.Format("[{{\"Name\":\"integrity\",\"Value\":\"sha256-{0}\"}}]", encodedIntegrity));
110115
projectEndpoints.Add(bundleEndpoint);
111116
112117
// for "_content/<ProjectName>/<Project Name>.<Fingerprint>.bundle.scp.css)
113118
var fingerPrintBundleEndpoint = new TaskItem(string.Format("_content/{0}/{0}.{1}.bundle.scp.css", appName, fingerprint));
114119
fingerPrintBundleEndpoint.SetMetadata("AssetFile", bundleScpCssPath);
115120
fingerPrintBundleEndpoint.SetMetadata("Selectors", "[]");
116-
fingerPrintBundleEndpoint.SetMetadata("ResponseHeaders", string.Format(resHeaderFormat, "max-age=31536000, immutable", fileInfo.Length, integrity, fileInfo.LastWriteTimeUtc));
121+
fingerPrintBundleEndpoint.SetMetadata("ResponseHeaders", string.Format(resHeaderFormat, "max-age=31536000, immutable", fileLength, integrity, lastWriteTime));
117122
fingerPrintBundleEndpoint.SetMetadata("EndpointProperties", string.Format("[{{\"Name\":\"fingerprint\",\"Value\":\"{0}\"}},{{\"Name\":\"integrity\",\"Value\":\"sha256-{1}\"}},{{\"Name\":\"label\",\"Value\":\"{2}\"}}]", fingerprint, encodedIntegrity, bundleEndpointIdentity));
118123
projectEndpoints.Add(fingerPrintBundleEndpoint);
119124
}

0 commit comments

Comments
 (0)