Skip to content

Commit f0f3dea

Browse files
committed
Normalize project.assets.json paths to fix ignores
1 parent 2aa451c commit f0f3dea

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks/UsageReport/WritePackageUsageData.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ public override bool Execute()
140140

141141
string[] assetFiles = Directory
142142
.GetFiles(RootDir, "project.assets.json", SearchOption.AllDirectories)
143-
.Except(IgnoredProjectAssetsJsonFiles.NullAsEmpty())
144-
.Select(path => path.Substring(RootDir.Length))
143+
.Select(GetPathRelativeToRoot)
144+
.Except(IgnoredProjectAssetsJsonFiles.NullAsEmpty().Select(GetPathRelativeToRoot))
145145
.ToArray();
146146

147147
if (!string.IsNullOrEmpty(ProjectAssetsJsonArchiveFile))
@@ -230,7 +230,7 @@ public override bool Execute()
230230
Usages = usages.ToArray(),
231231
NeverRestoredTarballPrebuilts = neverRestoredTarballPrebuilts,
232232
ProjectDirectories = ProjectDirectories
233-
?.Select(dir => dir.Substring(RootDir.Length))
233+
?.Select(GetPathRelativeToRoot)
234234
.ToArray()
235235
};
236236

@@ -244,6 +244,16 @@ public override bool Execute()
244244
return !Log.HasLoggedErrors;
245245
}
246246

247+
private string GetPathRelativeToRoot(string path)
248+
{
249+
if (path.StartsWith(RootDir))
250+
{
251+
return path.Substring(RootDir.Length).Replace(Path.DirectorySeparatorChar, '/');
252+
}
253+
254+
throw new ArgumentException($"Path '{path}' is not within RootDir '{RootDir}'");
255+
}
256+
247257
private static string[] ReadRidsFromRuntimeJson(string path)
248258
{
249259
var root = JObject.Parse(File.ReadAllText(path));

0 commit comments

Comments
 (0)