forked from loic-sharma/BaGet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c27656
commit 1b9da5b
Showing
10 changed files
with
206 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# BaGet SDK | ||
|
||
You can use BaGet's [`BaGet.Protocol`](https://www.nuget.org/packages/BaGet.Protocol) package to interact with a NuGet server. | ||
|
||
## Getting Started | ||
|
||
Install the [`BaGet.Protocol`](https://www.nuget.org/packages/BaGet.Protocol) package: | ||
|
||
``` | ||
dotnet add package BaGet.Protocol | ||
``` | ||
|
||
## List Package Versions | ||
|
||
Find all versions of the `Newtonsoft.Json` package: | ||
|
||
```csharp | ||
NuGetClient client = new NuGetClient("https://api.nuget.org/v3/index.json"); | ||
|
||
IReadOnlyList<NuGetVersion>> versions = await client.ListPackageVersionsAsync("Newtonsoft.Json"); | ||
|
||
foreach (NuGetVersion version in versions) | ||
{ | ||
Console.WriteLine($"Found version: {version}"); | ||
} | ||
``` | ||
|
||
## Download a package | ||
|
||
```csharp | ||
NuGetClient client = new NuGetClient("https://api.nuget.org/v3/index.json"); | ||
|
||
string packageId = "Newtonsoft.Json"; | ||
NuGetVersion packageVersion = new NuGetVersion("12.0.1"); | ||
|
||
using (Stream packageStream = await client.GetPackageStreamAsync(packageId, packageVersion)) | ||
{ | ||
Console.WriteLine($"Downloaded package {packageId} {packageVersion}"); | ||
} | ||
``` | ||
|
||
## Find Package Metadata | ||
|
||
```csharp | ||
NuGetClient client = new NuGetClient("https://api.nuget.org/v3/index.json"); | ||
|
||
// Find the metadata for all versions of a package. | ||
IReadOnlyList<PackageMetadata> items = await client.GetPackageMetadataAsync("Newtonsoft.Json"); | ||
if (!items.Any()) | ||
{ | ||
Console.WriteLine($"Package 'Newtonsoft.Json' does not exist"); | ||
return; | ||
} | ||
|
||
foreach (var metadata in items) | ||
{ | ||
Console.WriteLine($"Version: {metadata.Version}"); | ||
Console.WriteLine($"Listed: {metadata.Listed}"); | ||
Console.WriteLine($"Tags: {metadata.Tags}"); | ||
Console.WriteLine($"Description: {metadata.Description}"); | ||
} | ||
|
||
// Or, find the metadata for a single version of a package. | ||
string packageId = "Newtonsoft.Json" | ||
NuGetVersion packageVersion = new NuGetVersion("12.0.1"); | ||
|
||
PackageMetadata metadata = await client.GetPackageMetadataAsync(packageId, packageVersion); | ||
|
||
Console.WriteLine($"Listed: {metadata.Listed}"); | ||
Console.WriteLine($"Tags: {metadata.Tags}"); | ||
Console.WriteLine($"Description: {metadata.Description}"); | ||
``` | ||
|
||
## Search for packages | ||
|
||
Search for "json" packages: | ||
|
||
```csharp | ||
NuGetClient client = new NuGetClient("https://api.nuget.org/v3/index.json"); | ||
SearchResponse response = await client.SearchAsync("json"); | ||
|
||
Console.WriteLine($"Found {response.TotalHits} total results"); | ||
|
||
foreach (SearchResult searchResult in response.Data) | ||
{ | ||
Console.WriteLine($"Found package {searchResult.Id} {searchResult.Version}"); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.