12
12
using Microsoft . Build . Framework ;
13
13
using Microsoft . Build . Utilities ;
14
14
using NuGet . Common ;
15
- using NuGet . Frameworks ;
16
- using NuGet . Packaging ;
17
15
using NuGet . ProjectModel ;
18
16
using NuGet . Versioning ;
19
17
@@ -29,8 +27,6 @@ namespace Microsoft.NET.Build.Tasks
29
27
/// </summary>
30
28
public sealed class ResolvePackageAssets : TaskBase
31
29
{
32
- #region Input Items
33
-
34
30
/// <summary>
35
31
/// Path to assets.json.
36
32
/// </summary>
@@ -164,10 +160,6 @@ public sealed class ResolvePackageAssets : TaskBase
164
160
/// </summary>
165
161
public bool DesignTimeBuild { get ; set ; }
166
162
167
- #endregion
168
-
169
- #region Output Items
170
-
171
163
/// <summary>
172
164
/// Full paths to assemblies from packages to pass to compiler as analyzers.
173
165
/// </summary>
@@ -238,22 +230,9 @@ public sealed class ResolvePackageAssets : TaskBase
238
230
[ Output ]
239
231
public ITaskItem [ ] ApphostsForShimRuntimeIdentifiers { get ; private set ; }
240
232
241
- /// <summary>
242
- /// All the libraries/packages in the lock file.
243
- /// </summary>
244
- [ Output ]
245
- public ITaskItem [ ] PackageDefinitions { get ; private set ; }
246
-
247
233
[ Output ]
248
234
public ITaskItem [ ] PackageDependencies { get ; private set ; }
249
235
250
- /// <summary>
251
- /// All the dependencies between packages. Each package has metadata 'ParentPackage'
252
- /// to refer to the package that depends on it. For top level packages this value is blank.
253
- /// </summary>
254
- [ Output ]
255
- public ITaskItem [ ] PackageDependenciesBetweenPackages { get ; private set ; }
256
-
257
236
/// <summary>
258
237
/// List of symbol files (.pdb) related to NuGet packages.
259
238
/// </summary>
@@ -272,8 +251,6 @@ public sealed class ResolvePackageAssets : TaskBase
272
251
[ Output ]
273
252
public ITaskItem [ ] ReferenceDocumentationFiles { get ; private set ; }
274
253
275
- #endregion
276
-
277
254
/// <summary>
278
255
/// Messages from the assets file.
279
256
/// These are logged directly and therefore not returned to the targets (note private here).
@@ -358,9 +335,7 @@ private void ReadItemGroups()
358
335
FrameworkAssemblies = reader . ReadItemGroup ( ) ;
359
336
FrameworkReferences = reader . ReadItemGroup ( ) ;
360
337
NativeLibraries = reader . ReadItemGroup ( ) ;
361
- PackageDefinitions = reader . ReadItemGroup ( ) ;
362
338
PackageDependencies = reader . ReadItemGroup ( ) ;
363
- PackageDependenciesBetweenPackages = reader . ReadItemGroup ( ) ;
364
339
PackageFolders = reader . ReadItemGroup ( ) ;
365
340
ReferenceDocumentationFiles = reader . ReadItemGroup ( ) ;
366
341
ResourceAssemblies = reader . ReadItemGroup ( ) ;
@@ -679,8 +654,6 @@ internal sealed class CacheWriter : IDisposable
679
654
{
680
655
private const int InitialStringTableCapacity = 32 ;
681
656
682
- private HashSet < string > _projectFileDependencies ;
683
- private Dictionary < string , string > _targetNameToAliasMap ;
684
657
private ResolvePackageAssets _task ;
685
658
private BinaryWriter _writer ;
686
659
private LockFile _lockFile ;
@@ -711,8 +684,7 @@ public CacheWriter(ResolvePackageAssets task)
711
684
_task = task ;
712
685
_lockFile = new LockFileCache ( task ) . GetLockFile ( task . ProjectAssetsFile ) ;
713
686
_packageResolver = NuGetPackageResolver . CreateResolver ( _lockFile ) ;
714
- _targetNameToAliasMap = CreateTargetNameToAlisMap ( ) ;
715
- ReadProjectFileDependencies ( string . IsNullOrEmpty ( _task . TargetFramework ) || ! _targetNameToAliasMap . ContainsKey ( _task . TargetFramework ) ? null : _targetNameToAliasMap [ _task . TargetFramework ] ) ;
687
+
716
688
717
689
// If we are doing a design-time build, we do not want to fail the build if we can't find the
718
690
// target framework and/or runtime identifier in the assets file. This is because the design-time
@@ -754,26 +726,8 @@ public CacheWriter(ResolvePackageAssets task)
754
726
{
755
727
ComputePackageExclusions ( ) ;
756
728
}
757
-
758
- void ReadProjectFileDependencies ( string frameworkAlias )
759
- {
760
- _projectFileDependencies = _lockFile . GetProjectFileDependencySet ( frameworkAlias ) ;
761
- }
762
729
}
763
730
764
- private Dictionary < string , string > CreateTargetNameToAlisMap ( ) => _lockFile . Targets . ToDictionary ( t => t . Name , t =>
765
- {
766
- var alias = _lockFile . GetLockFileTargetAlias ( t ) ;
767
- if ( string . IsNullOrEmpty ( t . RuntimeIdentifier ) )
768
- {
769
- return alias ;
770
- }
771
- else
772
- {
773
- return alias + "/" + t . RuntimeIdentifier ;
774
- }
775
- } ) ;
776
-
777
731
public void WriteToCacheFile ( )
778
732
{
779
733
Directory . CreateDirectory ( Path . GetDirectoryName ( _task . ProjectAssetsCacheFile ) ) ;
@@ -852,9 +806,7 @@ private void WriteItemGroups()
852
806
WriteItemGroup ( WriteFrameworkAssemblies ) ;
853
807
WriteItemGroup ( WriteFrameworkReferences ) ;
854
808
WriteItemGroup ( WriteNativeLibraries ) ;
855
- WriteItemGroup ( WritePackageDefinitions ) ;
856
809
WriteItemGroup ( WritePackageDependencies ) ;
857
- WriteItemGroup ( WritePackageDependenciesBetweenPackages ) ;
858
810
WriteItemGroup ( WritePackageFolders ) ;
859
811
WriteItemGroup ( WriteReferenceDocumentationFiles ) ;
860
812
WriteItemGroup ( WriteResourceAssemblies ) ;
@@ -1205,13 +1157,17 @@ private void WriteDebugItems(
1205
1157
1206
1158
foreach ( string fileExtension in relatedExtensions . Split ( RelatedPropertySeparator ) )
1207
1159
{
1208
- if ( fileExtension . ToLowerInvariant ( ) == extension )
1160
+ if ( fileExtension . ToLower ( ) == extension )
1209
1161
{
1210
1162
string xmlFilePath = Path . ChangeExtension ( itemSpec , fileExtension ) ;
1211
1163
if ( File . Exists ( xmlFilePath ) )
1212
1164
{
1213
1165
WriteItem ( xmlFilePath , library ) ;
1214
1166
}
1167
+ else
1168
+ {
1169
+ _task . Log . LogWarning ( Strings . AssetsFileNotFound , xmlFilePath ) ;
1170
+ }
1215
1171
}
1216
1172
}
1217
1173
}
@@ -1438,72 +1394,6 @@ private void WritePackageFolders()
1438
1394
}
1439
1395
}
1440
1396
1441
- private void WritePackageDefinitions ( )
1442
- {
1443
- // Get library and file definitions
1444
- foreach ( var package in _lockFile . Libraries )
1445
- {
1446
- var packageName = package . Name ;
1447
- var packageVersion = package . Version . ToNormalizedString ( ) ;
1448
- string packageId = $ "{ packageName } /{ packageVersion } ";
1449
-
1450
- WriteItem ( packageId ) ;
1451
- WriteMetadata ( MetadataKeys . Name , packageName ) ;
1452
- WriteMetadata ( MetadataKeys . Type , package . Type ) ;
1453
- WriteMetadata ( MetadataKeys . Version , packageVersion ) ;
1454
- WriteMetadata ( MetadataKeys . Path , package . Path ?? string . Empty ) ;
1455
-
1456
- string resolvedPackagePath = ResolvePackagePath ( package ) ;
1457
- WriteMetadata ( MetadataKeys . ResolvedPath , resolvedPackagePath ?? string . Empty ) ;
1458
-
1459
- WriteMetadata ( MetadataKeys . DiagnosticLevel , GetPackageDiagnosticLevel ( package ) ) ;
1460
- }
1461
-
1462
- string ResolvePackagePath ( LockFileLibrary package )
1463
- {
1464
- if ( package . IsProject ( ) )
1465
- {
1466
- var relativeMSBuildProjectPath = package . MSBuildProject ;
1467
-
1468
- if ( string . IsNullOrEmpty ( relativeMSBuildProjectPath ) )
1469
- {
1470
- throw new BuildErrorException ( Strings . ProjectAssetsConsumedWithoutMSBuildProjectPath , package . Name , _task . ProjectAssetsFile ) ;
1471
- }
1472
-
1473
- return GetAbsolutePathFromProjectRelativePath ( relativeMSBuildProjectPath ) ;
1474
- }
1475
- else
1476
- {
1477
- return _packageResolver . GetPackageDirectory ( package . Name , package . Version ) ;
1478
- }
1479
- }
1480
-
1481
- string GetAbsolutePathFromProjectRelativePath ( string path )
1482
- {
1483
- return Path . GetFullPath ( Path . Combine ( Path . GetDirectoryName ( _task . ProjectPath ) , path ) ) ;
1484
- }
1485
-
1486
- string GetPackageDiagnosticLevel ( LockFileLibrary package )
1487
- {
1488
- string target = _task . TargetFramework ?? "" ;
1489
-
1490
- var messages = _lockFile . LogMessages . Where ( log => log . LibraryId == package . Name && log . TargetGraphs
1491
- . Select ( tg =>
1492
- {
1493
- var parsedTargetGraph = NuGetFramework . Parse ( tg ) ;
1494
- var alias = _lockFile . PackageSpec . TargetFrameworks . FirstOrDefault ( tf => tf . FrameworkName == parsedTargetGraph ) ? . TargetAlias ;
1495
- return alias ?? tg ;
1496
- } ) . Contains ( target ) ) ;
1497
-
1498
- if ( ! messages . Any ( ) )
1499
- {
1500
- return string . Empty ;
1501
- }
1502
-
1503
- return messages . Max ( log => log . Level ) . ToString ( ) ;
1504
- }
1505
- }
1506
-
1507
1397
private void WritePackageDependencies ( )
1508
1398
{
1509
1399
foreach ( var library in _runtimeTarget . Libraries )
@@ -1515,71 +1405,6 @@ private void WritePackageDependencies()
1515
1405
}
1516
1406
}
1517
1407
1518
- private void WritePackageDependenciesBetweenPackages ( )
1519
- {
1520
- foreach ( var target in _lockFile . Targets )
1521
- {
1522
- GetPackageDependencies ( target ) ;
1523
- }
1524
-
1525
- void GetPackageDependencies ( LockFileTarget target )
1526
- {
1527
- var resolvedPackageVersions = target . Libraries
1528
- . ToDictionary ( pkg => pkg . Name , pkg => pkg . Version . ToNormalizedString ( ) , StringComparer . OrdinalIgnoreCase ) ;
1529
-
1530
- string frameworkAlias = _targetNameToAliasMap [ target . Name ] ;
1531
-
1532
- var transitiveProjectRefs = new HashSet < string > (
1533
- target . Libraries
1534
- . Where ( lib => lib . IsTransitiveProjectReference ( _lockFile , ref _projectFileDependencies , frameworkAlias ) )
1535
- . Select ( pkg => pkg . Name ) ,
1536
- StringComparer . OrdinalIgnoreCase ) ;
1537
-
1538
- foreach ( var package in target . Libraries )
1539
- {
1540
- string packageId = $ "{ package . Name } /{ package . Version . ToNormalizedString ( ) } ";
1541
-
1542
- if ( _projectFileDependencies . Contains ( package . Name ) )
1543
- {
1544
- WriteItem ( packageId ) ;
1545
- WriteMetadata ( MetadataKeys . ParentTarget , frameworkAlias ) ; // Foreign Key
1546
- WriteMetadata ( MetadataKeys . ParentPackage , string . Empty ) ; // Foreign Key
1547
- }
1548
-
1549
- // get sub package dependencies
1550
- GetDependencies ( package , target . Name , resolvedPackageVersions , transitiveProjectRefs ) ;
1551
- }
1552
- }
1553
-
1554
- void GetDependencies (
1555
- LockFileTargetLibrary package ,
1556
- string targetName ,
1557
- Dictionary < string , string > resolvedPackageVersions ,
1558
- HashSet < string > transitiveProjectRefs )
1559
- {
1560
- string packageId = $ "{ package . Name } /{ package . Version . ToNormalizedString ( ) } ";
1561
- string frameworkAlias = _targetNameToAliasMap [ targetName ] ;
1562
- foreach ( var deps in package . Dependencies )
1563
- {
1564
- if ( ! resolvedPackageVersions . TryGetValue ( deps . Id , out string version ) )
1565
- {
1566
- continue ;
1567
- }
1568
-
1569
- string depsName = $ "{ deps . Id } /{ version } ";
1570
-
1571
- WriteItem ( depsName ) ;
1572
- WriteMetadata ( MetadataKeys . ParentTarget , frameworkAlias ) ; // Foreign Key
1573
- WriteMetadata ( MetadataKeys . ParentPackage , packageId ) ; // Foreign Key
1574
-
1575
- if ( transitiveProjectRefs . Contains ( deps . Id ) )
1576
- {
1577
- WriteMetadata ( MetadataKeys . TransitiveProjectReference , "true" ) ;
1578
- }
1579
- }
1580
- }
1581
- }
1582
-
1583
1408
private void WriteResourceAssemblies ( )
1584
1409
{
1585
1410
WriteItems (
0 commit comments