TFS 2010内置,删除本地而非分享位置

时间:2010-12-02 09:12:33

标签: build-automation tfs2010

我想将我构建的版本的构建文件复制到本地目录,而不是复制到unc共享。所以我写了一篇我想这样做的活动:

    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));
                    }
                );
        }
    }
}

但此活动失败,让我知道找不到该目录。怎么解决?我需要通过手动从二进制文件中获取seperat文件夹来进行自定义。

请求帮助, 迈克尔巴尔兹

1 个答案:

答案 0 :(得分:2)

为什么不使用基于localhost的unc路径?

\本地主机\ MYDIR

甚至

\本地主机\ C $ \ MYDIR

如果您想继续进行自定义活动,则可以非常轻松地进行调试。在具有指定值的单元测试(或使用例如控制台应用程序)中执行代码。启动此活动时,您确定源目录是否存在吗?您可以在代码中添加一些额外的检查(例如Directory.Exists)。 您还可以使用http://www.ewaldhofman.nl/post/2010/10/01/Customize-Team-Build-2010-e28093-Part-12-How-to-debug-my-custom-activities.aspx

调试代码