@@ -23,12 +23,12 @@ public sealed class PackageDataReader : IPackageDataReader
2323 public AssetsFilePath AssetsFilePath { get ; }
2424
2525 /// <summary>
26- /// Gets the target framework of the package .
26+ /// Gets the target framework of the project .
2727 /// </summary>
2828 public string TargetFramework { get ; }
2929
3030 /// <summary>
31- /// Gets the runtime identifier of the package (optional).
31+ /// Gets the runtime identifier of the project (optional).
3232 /// </summary>
3333 public string ? RuntimeIdentifier { get ; }
3434
@@ -41,9 +41,8 @@ public sealed class PackageDataReader : IPackageDataReader
4141 /// Initializes a new instance of the <see cref="PackageDataReader"/> class.
4242 /// </summary>
4343 /// <param name="assetsFilePath">The file path of the project assets file.</param>
44- /// <param name="targetFramework">The target framework of the package.</param>
45- /// <param name="runtimeIdentifier">The runtime identifier of the package (optional).</param>
46- /// <param name="knownPackageIds">Represents a collection of known package IDs and their associated owners or products (optional).</param>
44+ /// <param name="targetFramework">The target framework of the project.</param>
45+ /// <param name="runtimeIdentifier">The runtime identifier of the project (optional).</param>
4746 public PackageDataReader ( string assetsFilePath , string targetFramework , string ? runtimeIdentifier )
4847 : this ( new AssetsFilePath ( assetsFilePath ) , targetFramework , runtimeIdentifier )
4948 {
@@ -53,9 +52,8 @@ public PackageDataReader(string assetsFilePath, string targetFramework, string?
5352 /// Initializes a new instance of the <see cref="PackageDataReader"/> class.
5453 /// </summary>
5554 /// <param name="assetsFilePath">The file path of the project assets file.</param>
56- /// <param name="targetFramework">The target framework of the package.</param>
57- /// <param name="runtimeIdentifier">The runtime identifier of the package (optional).</param>
58- /// <param name="knownPackageIds">Represents a collection of known package IDs and their associated owners or products (optional).</param>
55+ /// <param name="targetFramework">The target framework of the project.</param>
56+ /// <param name="runtimeIdentifier">The runtime identifier of the project (optional).</param>
5957 public PackageDataReader ( AssetsFilePath assetsFilePath , string targetFramework , string ? runtimeIdentifier )
6058 {
6159 ThrowHelper . ThrowIfNullOrEmpty ( targetFramework ) ;
@@ -74,14 +72,16 @@ public IReadOnlyCollection<IPackageData> Read(CancellationToken cancellationToke
7472 {
7573 cancellationToken . ThrowIfCancellationRequested ( ) ;
7674
77- NuGetFramework framework = NuGetFramework . Parse ( TargetFramework ) ;
7875 LockFile lockFile = AssetsFilePath . ReadLockFile ( ) ;
7976
77+ NuGetFramework framework = GetFramework ( lockFile , TargetFramework )
78+ ?? throw new InvalidOperationException ( $ "No target framework was found for the alias '{ TargetFramework } '.") ;
79+
8080 IList < LibraryDependency > projectDependencies = lockFile . PackageSpec
8181 . GetTargetFramework ( framework )
8282 . Dependencies ;
8383
84- LockFileTarget ? target = TryGetTarget ( lockFile , framework )
84+ LockFileTarget ? target = TryGetTarget ( lockFile , framework , RuntimeIdentifier )
8585 ?? throw new InvalidOperationException ( $ "No target was found for the target framework '{ TargetFramework } ' and the runtime id '{ RuntimeIdentifier } '.") ;
8686
8787 List < IPackageData > result = new ( ) ;
@@ -121,11 +121,18 @@ public IReadOnlyCollection<IPackageData> Read(CancellationToken cancellationToke
121121
122122 return result ;
123123
124- LockFileTarget TryGetTarget ( LockFile lockFile , NuGetFramework framework )
124+ static NuGetFramework ? GetFramework ( LockFile lockFile , string targetFramework )
125+ {
126+ return lockFile . PackageSpec . TargetFrameworks
127+ . FirstOrDefault ( tfi => tfi . TargetAlias . Equals ( targetFramework , StringComparison . OrdinalIgnoreCase ) )
128+ ? . FrameworkName ;
129+ }
130+
131+ static LockFileTarget TryGetTarget ( LockFile lockFile , NuGetFramework framework , string ? runtimeIdentifier )
125132 {
126- return string . IsNullOrEmpty ( RuntimeIdentifier )
133+ return string . IsNullOrEmpty ( runtimeIdentifier )
127134 ? lockFile . GetTarget ( framework , null )
128- : lockFile . GetTarget ( framework , RuntimeIdentifier )
135+ : lockFile . GetTarget ( framework , runtimeIdentifier )
129136 ?? lockFile . GetTarget ( framework , null ) ;
130137 }
131138 }
0 commit comments