@@ -64,6 +64,12 @@ public class WritePackageUsageData : Task
64
64
[ Required ]
65
65
public string RootDir { get ; set ; }
66
66
67
+ /// <summary>
68
+ /// project.assets.json files to ignore, for example, because they are checked-in assets not
69
+ /// generated during source-build and cause false positives.
70
+ /// </summary>
71
+ public string [ ] IgnoredProjectAssetsJsonFiles { get ; set ; }
72
+
67
73
/// <summary>
68
74
/// Output usage data JSON file path.
69
75
/// </summary>
@@ -132,10 +138,11 @@ public override bool Execute()
132
138
133
139
Log . LogMessage ( MessageImportance . Low , "Finding project.assets.json files..." ) ;
134
140
135
- string [ ] assetFiles = Directory . GetFiles (
136
- RootDir ,
137
- "project.assets.json" ,
138
- SearchOption . AllDirectories ) ;
141
+ string [ ] assetFiles = Directory
142
+ . GetFiles ( RootDir , "project.assets.json" , SearchOption . AllDirectories )
143
+ . Select ( path => path . Substring ( RootDir . Length ) )
144
+ . Except ( IgnoredProjectAssetsJsonFiles . NullAsEmpty ( ) )
145
+ . ToArray ( ) ;
139
146
140
147
if ( ! string . IsNullOrEmpty ( ProjectAssetsJsonArchiveFile ) )
141
148
{
@@ -152,10 +159,9 @@ public override bool Execute()
152
159
{
153
160
// Only one entry can be open at a time, so don't do this during the Parallel
154
161
// ForEach later.
155
- foreach ( var file in assetFiles )
162
+ foreach ( var relativePath in assetFiles )
156
163
{
157
- string relativePath = file . Substring ( RootDir . Length ) ;
158
- using ( var stream = File . OpenRead ( file ) )
164
+ using ( var stream = File . OpenRead ( Path . Combine ( RootDir , relativePath ) ) )
159
165
using ( Stream entryWriter = projectAssetArchive
160
166
. CreateEntry ( relativePath , CompressionLevel . Optimal )
161
167
. Open ( ) )
@@ -176,7 +182,7 @@ public override bool Execute()
176
182
{
177
183
var properties = new HashSet < string > ( StringComparer . OrdinalIgnoreCase ) ;
178
184
179
- using ( var file = File . OpenRead ( assetFile ) )
185
+ using ( var file = File . OpenRead ( Path . Combine ( RootDir , assetFile ) ) )
180
186
using ( var reader = new StreamReader ( file ) )
181
187
using ( var jsonReader = new JsonTextReader ( reader ) )
182
188
{
@@ -194,8 +200,7 @@ public override bool Execute()
194
200
. Where ( id => properties . Contains ( id . Id + "/" + id . Version . OriginalVersion ) ) )
195
201
{
196
202
usages . Add ( Usage . Create (
197
- // Store relative path for future report generation.
198
- assetFile . Substring ( RootDir . Length ) ,
203
+ assetFile ,
199
204
identity ,
200
205
possibleRids ) ) ;
201
206
}
0 commit comments