@@ -53,13 +53,54 @@ public NuGetClient(NuGetClientFactory clientFactory)
53
53
_clientFactory = clientFactory ?? throw new ArgumentNullException ( nameof ( clientFactory ) ) ;
54
54
}
55
55
56
+ /// <summary>
57
+ /// Check if a package exists.
58
+ /// </summary>
59
+ /// <param name="packageId">The package ID.</param>
60
+ /// <param name="cancellationToken">A token to cancel the task.</param>
61
+ /// <returns>Whether the package exists.</returns>
62
+ public virtual async Task < bool > ExistsAsync (
63
+ string packageId ,
64
+ CancellationToken cancellationToken = default )
65
+ {
66
+ var client = await _clientFactory . CreatePackageContentClientAsync ( cancellationToken ) ;
67
+ var versions = await client . GetPackageVersionsOrNullAsync ( packageId , cancellationToken ) ;
68
+
69
+ return ( versions != null && versions . Versions . Any ( ) ) ;
70
+ }
71
+
72
+ /// <summary>
73
+ /// Check if a package exists.
74
+ /// </summary>
75
+ /// <param name="packageId">The package ID.</param>
76
+ /// <param name="packageVersion">The package version.</param>
77
+ /// <param name="cancellationToken">A token to cancel the task.</param>
78
+ /// <returns>Whether the package exists.</returns>
79
+ public virtual async Task < bool > ExistsAsync (
80
+ string packageId ,
81
+ NuGetVersion packageVersion ,
82
+ CancellationToken cancellationToken = default )
83
+ {
84
+ var client = await _clientFactory . CreatePackageContentClientAsync ( cancellationToken ) ;
85
+ var versions = await client . GetPackageVersionsOrNullAsync ( packageId , cancellationToken ) ;
86
+
87
+ if ( versions == null )
88
+ {
89
+ return false ;
90
+ }
91
+
92
+ return versions
93
+ . ParseVersions ( )
94
+ . Any ( v => v == packageVersion ) ;
95
+ }
96
+
56
97
/// <summary>
57
98
/// Download a package (.nupkg), or throws if the package does not exist.
58
99
/// </summary>
59
100
/// <param name="packageId">The package ID.</param>
60
101
/// <param name="packageVersion">The package version.</param>
61
102
/// <param name="cancellationToken">A token to cancel the task.</param>
62
- /// <returns>The package's content stream. The stream may not be seekable .</returns>
103
+ /// <returns>The package's content stream. The stream may be unseekable and may be unbuffered .</returns>
63
104
/// <exception cref="PackageNotFoundException">
64
105
/// The package could not be found.
65
106
/// </exception>
0 commit comments