1

I am looking to remotely fire a delete command using the MSDeploy API through c# code.

I want to achieve the following command:

msdeploy.exe -verb:delete -dest:contentPath="/folderName/filename.txt"

instead of through running an unmanaged external executable, I want to execute this using the MSDeploy .Net API.

2 Answers 2

2

Assuming you're trying to delete an absolute filepath (rather than a file in a website), you're looking for something like this:

DeploymentObject destObject = DeploymentManager.CreateObject(
    DeploymentWellKnownProvider.FilePath, "/foldername/filename.txt");

DeploymentObject sourceObject = DeploymentManager.CreateObject("auto", "");

DeploymentBaseOptions baseOptions = new DeploymentBaseOptions();
DeploymentSyncOptions syncOptions = new DeploymentSyncOptions
{
    DeleteDestination = true;
};

DeploymentChangeSummary results = sourceObject.SyncTo(
   destObject, baseOptions, syncOptions);

// results.ObjectsDeleted == 1
Sign up to request clarification or add additional context in comments.

1 Comment

These overloads don't appear to exist. SyncTo doesn't take in a DeploymentObject.
0

I've found the answer thanks to Richard Szalay's leading and i've used the ContentPath provider as this is a common provider used by VS Publishing so the chances of having permissions is high:

var deployBaseOptions = new DeploymentBaseOptions
{
    ComputerName = "https://mywebserver.com:8172/msdeploy.axd?sitename=yourIISWebsiteName",
    UserName = "username",
    Password = "password",
    UseDelegation = true,
    AuthenticationType = "Basic"
};
var syncOptions = new DeploymentSyncOptions
{
    DeleteDestination = true
};
var deploymentObject = DeploymentManager.CreateObject(DeploymentWellKnownProvider.ContentPath,
                                                        "yourIISWebsiteName" + "/fileToDelete.txt",
                                                        destBaseOptions);

var results = deploymentObject.SyncTo(deployBaseOptions, syncOptions);

The weird thing is that results always shows 3 files deleted even when there is only one...?!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.