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 sourceCred = new Mock<ICredentialProvider>();
var sourceRepository = new Repository(new RepositoryOptions
{
    Reference = Reference.Parse("source.io/testrepository"),
    Client = new Client(httpClient, credentialProvider: sourceCred.Object),
});

// 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, "");