This library is a work-in-progress set of utilities for working with Universal Packages and feeds.
Add a reference to Inedo.UPack using NuGet package manager.
Use the UniversalPackageBuilder
class to create a new .upack
file:
var metadata = new UniversalPackageMetadata
{
Group = "my/group",
Name = "MyPackage",
Version = UniversalPackageVersion.Parse("1.0.0"),
Title = "My Test Package",
Description = "This is where a useful description would go.",
["_customProperty"] = "I am a custom, extended property."
};
using (var builder = new UniversalPackageBuilder("MyPackage.upack", metadata))
{
// Recursively add all files and directories from C:\Test\MyFiles to the package
await builder.AddContentsAsync(@"C:\Test\MyFiles", "", true);
}
Create an instance of the UniversalPackage
class:
using (var package = new UniversalPackage("MyPackage.upack"))
{
}
Access the properties on a UniversalPackage
instance:
Console.WriteLine($"Package name: {package.Name}");
Console.WriteLine($"Package version: {package.Version}");
// The UniversalPackage class only provides basic metadata.
// To get a copy of all metadata, call the GetFullMetadata method.
var fullMetadata = package.GetFullMetadata();
Console.WriteLine($"Package title: {fullMetadata.Title}");
Use the ExtractContentItemsAsync
method on a UniversalPackage
instance:
await package.ExtractContentItemsAsync(@"C:\Test\UnpackedPackage");
Use the GetRegistry
method on the PackageRegistry
class:
using (var registry = PackageRegistry.GetRegistry(true /*true for user registry*/))
{
}
Lock the package registry and call the RegisterPackageAsync
method on a PackageRegistry
instance:
await registry.LockAsync();
await registry.RegisterPackageAsync(
new RegisteredPackage
{
Group = "my/group",
Name = "MyPackage",
Version = "1.0.0",
InstallPath = @"C:\Test\UnpackedPackage",
InstallationDate = DateTimeOffset.Now.ToString("o"),
InstallationReason = "No reason - just a test!",
InstalledUsing = "My upack client",
InstalledBy = "Steve"
}
);
Call the GetInstalledPackagesAsync
method on a PackageRegistry
instance:
foreach (var p in await registry.GetInstalledPackagesAsync())
Console.WriteLine($"{p.Name} {p.Version}");
Create a new instance of the UniversalFeedClient
class:
var feed = new UniversalFeedClient("http://upack.example.com/feed");
Call ListPackagesAsync
on a UniversalFeedClient
instance:
var packages = await feed.ListPackagesAsync("my/group", null);
Call GetPackageStreamAsync
on a UniversalFeedClient
instance to get a stream:
using (var packageStream = await feed.GetPackageStreamAsync(UniversalPackageId.Parse("my/group/MyPackage"), UniversalPackageVersion.Parse("1.0.0")))
using (var fileStream = File.Create(@"C:\Test\DownloadedPackage.upack"))
{
await packageStream.CopyToAsync(fileStream);
}
Call UploadPackageAsync
on a UniversalFeedClient
instance:
using (var fileStream = File.OpenRead(@"C:\Test\SourcePackage.upack"))
{
await feed.UploadPackageAsync(fileStream);
}