Table of Contents

Copy an artifact from a remote repository to another

// This example demonstrates how to copy an artifact from one repository to another.

// Create a HttpClient instance to be used for making HTTP requests.
var httpClient = new HttpClient();

// Source repository
var mockCredentialProvider = new Mock<ICredentialProvider>();
var memoryCache = new MemoryCache(new MemoryCacheOptions());
var sourceRepository = new Repository(new RepositoryOptions
{
    Reference = Reference.Parse("source.io/testrepository"),
    Client = new Client(httpClient, credentialProvider: mockCredentialProvider.Object, new Cache(memoryCache)),
});

// Destination repository
var destinationCred = new Mock<ICredentialProvider>();
var destRepository = new Repository(new RepositoryOptions
{
    Reference = Reference.Parse("target.io/testrepository"),
    Client = new Client(httpClient, credentialProvider: destinationCred.Object)
});

// Copy the artifact tagged by reference from the source repository to the destination
var reference = "tag";
var rootDescriptor = await sourceRepository.CopyAsync(reference, destRepository, "");