i have wanted to copy the built files on my release built to a local directory, not to an unc share. So i have written an activity which i wanted to do so:
using System.Activities;
using System.IO;
using System.Linq;
using Microsoft.TeamFoundation.Build.Client;
namespace CustomBuiltActivities
{
/// <summary>
/// This activity helps to copy a directory to another one. Integrated in TeamFoundation built activities are only supporting
/// copy to an unc share, so this is a small helper activity we need for copying files to an local directory.
/// </summary>
[BuildActivity(HostEnvironmentOption.Agent)]
public sealed class CopyDirectoryLocal : CodeActivity
{
[RequiredArgument]
public InArgument<string> DestinationDirectory { get; set; }
[RequiredArgument]
public InArgument<string> SourceDirectory { get; set; }
protected override void Execute(CodeActivityContext context)
{
var destination = context.GetValue(DestinationDirectory);
var source = context.GetValue(SourceDirectory);
CopyRecursive(source, destination);
}
private static void CopyRecursive(string sourceDirectory, string destinationDirectory)
{
if (!Directory.Exists(sourceDirectory))
throw new DirectoryNotFoundException(sourceDirectory);
try
{
Directory.CreateDirectory(destinationDirectory);
}
catch
{
}
Directory.GetDirectories(sourceDirectory).ToList().ForEach(
sourceDir =>
{
var dirName = sourceDir.Substring(sourceDir.LastIndexOf("\\"));
CopyRecursive(sourceDir, destinationDirectory+"\\"+dirName);
});
Directory.GetFiles(sourceDirectory).ToList().ForEach(
sourceFile =>
{
var fileName = new FileInfo(sourceFile).Name;
File.Copy(sourceFile, string.Concat(destinationDirectory, "\\", fileName));
}
);
}
}
}
But this activity fails and let me know that the directory was not found. How to fix it? I need customization by getting seperat folders in from the binaries manually out there.
Thx for help,
Michael Baarz
Why do you not use a unc path based on localhost?
\localhost\MyDir
or even
\localhost\c$\mydir
If you want to proceed with your custom activity, it is pretty easy to debug. Execute the code in a unit test (or with eg a console app) with the specified values. Are you sure that the source directory exists when you start this activity? You could add some additional checks (such as Directory.Exists) in your code.
You could also debug your code with http://www.ewaldhofman.nl/post/2010/10/01/Customize-Team-Build-2010-e28093-Part-12-How-to-debug-my-custom-activities.aspx