.NET Zone is brought to you in partnership with:

Doug Rathbone is a software architect working in Ad land. He is passionate about software design and automation, and regularly contributes to a number of industry sites on these topics. Douglas is a DZone MVB and is not an employee of DZone and has posted 61 posts at DZone. You can read more from them at their website. View Full User Profile

SimpleDeploy.Net - An FTP Style Wrapper for the MS Deploy API

01.08.2013
| 2694 views |
  • submit to reddit

MS Deploy is such a powerful tool when used to keep your applications and services up to date. What is even more awesome is that the API for MS Deploy is available for you to write applications that utilise this power from within your own applications. As most people who’ve played with MS Deploy can report though, whether you’re using MSBUILD, PowerShell or the .Net API; The MS Deploy API sucks when it comes to simplicity. So after trial and error and much head banging I’ve created a wrapper for MS Deploy’s API to help you complete simple tasks with less friction.

imageI've spent a fair bit of my personal time working on a personal project that I'll be releasing in the next few months. It involves the use of the MS Deploy API for deployment. I’ve had to get very close to the API that MS Deploy makes available, and in doing so have come to have a love/hate relationship with how it has been written.

MS Deploy contains a very powerful toolset but file upload and download is definitely only the tip of iceberg of this functionality. This is my problem. The team who wrote the API appears to have been so involved with the bigger problems, that the act of simply uploading a file to a remote server is a painfully long winded and hard to understand task:

Ms Deploy API Upload Example:

var destinationOptions = new DeploymentBaseOptions
{
    ComputerName = "https://myserver.com:8172/msdeploy.axd?site=[MyIISWebSiteName]",
    UserName = "myUsername",
    Password = "myOoberSecurePassword",
    UseDelegation = true,
    AuthenticationType = "Basic"
};

var syncOptions = new DeploymentSyncOptions { DoNotDelete = true };

var remotePath = String.Format("{0}/{1}", "[MyIISWebsiteName", "theRemoteFilePathToSaveTo.txt");

using (var localFile = DeploymentManager.CreateObject(DeploymentWellKnownProvider.ContentPath, @"C:\temp\fileToUpload.txt"))
{
    var result = localFile.SyncTo(DeploymentWellKnownProvider.ContentPath, remotePath, destinationOptions, syncOptions);
    //if (result.ObjectsAdded == 1 || result.ObjectsUpdated == 1) everything has worked
}

Welcome SimpleDeploy.Net

So I took the liberty of making it easier for people like me who just want to freekin-upload-some-files. I haven’t looked back.

SimplyDeploy.Net is a very simply library with 4 simple methods:

public DeploymentObjectList FetchFileList(ConnectionProperties properties)
public bool DownloadFile(ConnectionProperties properties, string relativeRemoteFileName, string fullLocalFilePathToSave)
public bool UploadFile(ConnectionProperties properties, string relativeDestinationFileName, string fullLocalFilePath)
public bool DeleteFile(ConnectionProperties properties, string relativeRemoteFileName)

It uses the ContentPath WebDeploy provider to make all of its remote calls in keeping with Visual Studio 2012’s Web Deploy Publishing Profile support. Hopefully this will allow for the most coverage from servers/sites that already support this.

Getting it

It is released under MS-PL so is fine for commercial use.

Either download the source from GitHub - https://github.com/dougrathbone/simpledeploynet

Or install using NuGet:

image

Published at DZone with permission of Douglas Rathbone, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)