@@ -216,7 +216,7 @@ public void ItHandlesReferenceAndPackageReferenceNameCollisions()
216
216
}
217
217
218
218
// If an assembly is in withResources, it has to be a key in dependencies, even with an empty list.
219
- private static DependencyContext BuildDependencyContextFromDependenciesWithResources ( Dictionary < string , List < string > > dependencies , List < string > withResources , List < string > references )
219
+ private static DependencyContext BuildDependencyContextFromDependenciesWithResources ( Dictionary < string , List < string > > dependencies , List < string > withResources , List < string > references , bool dllReference )
220
220
{
221
221
string mainProjectName = "simpleApp" ;
222
222
LockFile lockFile = TestLockFiles . GetLockFile ( mainProjectName ) ;
@@ -229,43 +229,49 @@ private static DependencyContext BuildDependencyContextFromDependenciesWithResou
229
229
[ ] ) ;
230
230
string mainProjectDirectory = Path . GetDirectoryName ( mainProject . ProjectPath ) ;
231
231
232
- ITaskItem [ ] referencePaths = references . Select ( reference =>
232
+
233
+ ITaskItem [ ] referencePaths = dllReference ? references . Select ( reference =>
233
234
new MockTaskItem ( $ "/usr/Path/{ reference } .dll", new Dictionary < string , string > {
234
235
{ "CopyLocal" , "false" } ,
235
236
{ "FusionName" , $ "{ reference } , Version=4.0.0.0, Culture=neutral, PublicKeyToken=null" } ,
236
237
{ "Version" , "" } ,
237
- } ) ) . ToArray ( ) ;
238
+ } ) ) . ToArray ( ) : [ ] ;
238
239
239
240
ProjectContext projectContext = lockFile . CreateProjectContext (
240
- FrameworkConstants . CommonFrameworks . NetCoreApp10 . GetShortFolderName ( ) ,
241
+ FrameworkConstants . CommonFrameworks . Net10_0 . GetShortFolderName ( ) ,
241
242
runtime : null ,
242
243
platformLibraryName : Constants . DefaultPlatformLibrary ,
243
244
runtimeFrameworks : null ,
244
245
isSelfContained : false ) ;
245
246
247
+ if ( ! dllReference )
248
+ {
249
+ projectContext . LockFile . ProjectFileDependencyGroups . Add ( new ProjectFileDependencyGroup ( string . Empty , references ) ) ;
250
+ }
251
+
246
252
Dictionary < string , SingleProjectInfo > referenceProjectInfos = new ( ) ;
247
253
248
254
foreach ( KeyValuePair < string , List < string > > kvp in dependencies )
249
255
{
250
- projectContext . LockFileTarget . Libraries . Add (
256
+ projectContext . LockFileTarget . Libraries = projectContext . LockFileTarget . Libraries . Concat ( [
251
257
new LockFileTargetLibrary ( )
252
258
{
253
259
Name = kvp . Key ,
254
260
Version = new NuGetVersion ( 4 , 0 , 0 ) ,
255
261
Type = withResources . Contains ( kvp . Key ) ? "project" : "unrealType" ,
256
262
Dependencies = kvp . Value . Select ( n => new PackageDependency ( n ) ) . ToList ( )
257
- } ) ;
263
+ } ] ) . ToList ( ) ;
258
264
259
265
if ( withResources . Contains ( kvp . Key ) )
260
266
{
261
267
var fullPath = Path . GetFullPath ( Path . Combine ( mainProjectDirectory , kvp . Key ) ) ;
262
- lockFile . Libraries . Add ( new LockFileLibrary ( )
268
+ lockFile . Libraries = lockFile . Libraries . Concat ( [ new LockFileLibrary ( )
263
269
{
264
270
Name = kvp . Key ,
265
271
Version = new NuGetVersion ( 4 , 0 , 0 ) ,
266
272
Type = "project" ,
267
273
MSBuildProject = fullPath
268
- } ) ;
274
+ } ] ) . ToList ( ) ;
269
275
270
276
referenceProjectInfos . Add ( fullPath , SingleProjectInfo . Create ( kvp . Key , kvp . Key , ".dll" , "4.0.0" ,
271
277
[ new MockTaskItem ( $ "{ kvp . Key } .resource", new Dictionary < string , string > ( ) {
@@ -284,86 +290,100 @@ private static DependencyContext BuildDependencyContextFromDependenciesWithResou
284
290
. Build ( ) ;
285
291
}
286
292
287
- [ Fact ]
288
- public void DirectReferenceToPackageWithNoAssets ( )
293
+ [ Theory ]
294
+ [ InlineData ( true ) ]
295
+ [ InlineData ( false ) ]
296
+ public void DirectReferenceToPackageWithNoAssets ( bool dllReference )
289
297
{
290
- DependencyContext dependencyContext = BuildDependencyContextFromDependenciesWithResources ( [ ] , [ ] , [ "System.A" ] ) ;
298
+ DependencyContext dependencyContext = BuildDependencyContextFromDependenciesWithResources ( [ ] , [ ] , [ "System.A" ] , dllReference ) ;
291
299
Save ( dependencyContext ) ;
292
300
dependencyContext . RuntimeLibraries . Count . Should ( ) . Be ( 1 ) ;
293
301
}
294
302
295
- [ Fact ]
296
- public void IndirectReferenceToPackageWithNoAssets ( )
303
+ [ Theory ]
304
+ [ InlineData ( true ) ]
305
+ [ InlineData ( false ) ]
306
+ public void IndirectReferenceToPackageWithNoAssets ( bool dllReference )
297
307
{
298
308
DependencyContext dependencyContext = BuildDependencyContextFromDependenciesWithResources ( new Dictionary < string , List < string > > ( ) {
299
309
{ "System.A" , [ "System.B" ] }
300
- } , [ "System.A" ] , [ "System.A" ] ) ;
310
+ } , [ "System.A" ] , [ "System.A" ] , dllReference ) ;
301
311
Save ( dependencyContext ) ;
302
312
dependencyContext . RuntimeLibraries . Count . Should ( ) . Be ( 2 ) ;
303
313
dependencyContext . RuntimeLibraries . Should ( ) . Contain ( x => x . Name . Equals ( "System.A" ) ) ;
304
314
}
305
315
306
- [ Fact ]
307
- public void PackageWithNoAssetsReferencesPackageWithNoAssets ( )
316
+ [ Theory ]
317
+ [ InlineData ( true ) ]
318
+ [ InlineData ( false ) ]
319
+ public void PackageWithNoAssetsReferencesPackageWithNoAssets ( bool dllReference )
308
320
{
309
321
DependencyContext dependencyContext = BuildDependencyContextFromDependenciesWithResources ( new Dictionary < string , List < string > > ( ) {
310
322
{ "System.A" , [ "System.B" ] } ,
311
323
{ "System.B" , [ ] }
312
- } , [ ] , [ "System.A" ] ) ;
324
+ } , [ ] , [ "System.A" ] , dllReference ) ;
313
325
Save ( dependencyContext ) ;
314
326
dependencyContext . RuntimeLibraries . Count . Should ( ) . Be ( 1 ) ;
315
327
}
316
328
317
- [ Fact ]
318
- public void PackageWithNoAssetsReferencesPackageWithAssets ( )
329
+ [ Theory ]
330
+ [ InlineData ( true ) ]
331
+ [ InlineData ( false ) ]
332
+ public void PackageWithNoAssetsReferencesPackageWithAssets ( bool dllReference )
319
333
{
320
334
DependencyContext dependencyContext = BuildDependencyContextFromDependenciesWithResources ( new Dictionary < string , List < string > > ( ) {
321
335
{ "System.A" , [ "System.B" ] } ,
322
336
{ "System.B" , [ ] }
323
- } , [ "System.B" ] , [ "System.A" ] ) ;
337
+ } , [ "System.B" ] , [ "System.A" ] , dllReference ) ;
324
338
Save ( dependencyContext ) ;
325
339
dependencyContext . RuntimeLibraries . Count . Should ( ) . Be ( 3 ) ;
326
340
dependencyContext . RuntimeLibraries . Should ( ) . Contain ( x => x . Name . Equals ( "System.A" ) ) ;
327
341
dependencyContext . RuntimeLibraries . Should ( ) . Contain ( x => x . Name . Equals ( "System.B" ) ) ;
328
342
}
329
343
330
- [ Fact ]
331
- public void PackageWithNoAssetsReferencesPackageReferencesByOtherPackage ( )
344
+ [ Theory ]
345
+ [ InlineData ( true ) ]
346
+ [ InlineData ( false ) ]
347
+ public void PackageWithNoAssetsReferencesPackageReferencesByOtherPackage ( bool dllReference )
332
348
{
333
349
DependencyContext dependencyContext = BuildDependencyContextFromDependenciesWithResources ( new Dictionary < string , List < string > > ( )
334
350
{
335
351
{ "System.A" , [ "System.B" ] } ,
336
352
{ "System.B" , [ ] } ,
337
- } , [ "System.B" ] , [ "System.A" , "System.B" ] ) ;
353
+ } , [ "System.B" ] , [ "System.A" , "System.B" ] , dllReference ) ;
338
354
Save ( dependencyContext ) ;
339
355
dependencyContext . RuntimeLibraries . Count . Should ( ) . Be ( 2 ) ;
340
356
dependencyContext . RuntimeLibraries . Should ( ) . Contain ( x => x . Name . Equals ( "System.B" ) ) ;
341
357
}
342
358
343
- [ Fact ]
344
- public void PackageWithNoAssetsReferencesPackageWithAssetsWithOtherReferencer ( )
359
+ [ Theory ]
360
+ [ InlineData ( true ) ]
361
+ [ InlineData ( false ) ]
362
+ public void PackageWithNoAssetsReferencesPackageWithAssetsWithOtherReferencer ( bool dllReference )
345
363
{
346
364
DependencyContext dependencyContext = BuildDependencyContextFromDependenciesWithResources ( new Dictionary < string , List < string > > ( )
347
365
{
348
366
{ "System.A" , [ "System.B" ] } ,
349
367
{ "System.B" , [ ] } ,
350
368
{ "System.C" , [ "System.B" ] }
351
- } , [ "System.B" , "System.C" ] , [ "System.A" , "System.C" ] ) ;
369
+ } , [ "System.B" , "System.C" ] , [ "System.A" , "System.C" ] , dllReference ) ;
352
370
Save ( dependencyContext ) ;
353
371
dependencyContext . RuntimeLibraries . Count . Should ( ) . Be ( 3 ) ;
354
372
dependencyContext . RuntimeLibraries . Should ( ) . Contain ( x => x . Name . Equals ( "System.C" ) ) ;
355
373
dependencyContext . RuntimeLibraries . Should ( ) . Contain ( x => x . Name . Equals ( "System.B" ) ) ;
356
374
}
357
375
358
- [ Fact ]
359
- public void TwoPackagesWithNoAssetsReferencePackageWithAssets ( )
376
+ [ Theory ]
377
+ [ InlineData ( true ) ]
378
+ [ InlineData ( false ) ]
379
+ public void TwoPackagesWithNoAssetsReferencePackageWithAssets ( bool dllReference )
360
380
{
361
381
DependencyContext dependencyContext = BuildDependencyContextFromDependenciesWithResources ( new Dictionary < string , List < string > > ( )
362
382
{
363
383
{ "System.A" , [ "System.B" ] } ,
364
384
{ "System.C" , [ "System.B" ] } ,
365
385
{ "System.B" , [ ] }
366
- } , [ "System.B" ] , [ "System.A" , "System.C" ] ) ;
386
+ } , [ "System.B" ] , [ "System.A" , "System.C" ] , dllReference ) ;
367
387
Save ( dependencyContext ) ;
368
388
dependencyContext . RuntimeLibraries . Count . Should ( ) . Be ( 3 ) ;
369
389
dependencyContext . RuntimeLibraries . Should ( ) . Contain ( x => x . Name . Equals ( "System.B" ) ) ;
0 commit comments