Question

I see lots of posts for waiting on the return value of various activities, but in this case, I'd like to kick off an activity and then not wait. I just want to copy a directory over a (very) slow network, so I'd prefer not to create another activity or use a batch script for this. Anyone done this? Is there a clean way? I could cobble something together, but I'm trying to keep this as vanilla as possible.

Était-ce utile?

La solution

I don't think that something out of the box is available for you to use.

One way to proceed is to organize an "Invoke Process" that invokes another service that does the actual copying. So from within Build you advance and let the invoked entity (that is out of scope in terms of TFS build) do the actual activity. This does come with certain deficiencies, the more important being that you won't ever know in your build-logs if this succeeded or failed.

Another option is to use the Parallel activity (it's in the Toolbox under "Control Flow" - System.Activities.Statements.Parallel). This is not quite like what you need (kick & forget), still it could allow you to do other stuff while your copy happens.

Autres conseils

Here is simple custom activity that will create new process:

[BuildActivity (HostEnvironmentOption.All)]
public sealed class InvokeProcessAsync : CodeActivity
{
    [RequiredArgument]
    public InArgument<string> FileName { get; set; }

    public InArgument<string> Arguments { get; set; }

    public InArgument<string> WorkingDirectory { get; set; }

    public InArgument<IDictionary<string, string>> EnvironmentVariables { get; set; }



    protected override void Execute (CodeActivityContext context)
    {
        context.DublicateOperationsLogsToBuildOutput ();

        var psi = new ProcessStartInfo
        {
            FileName = context.GetValue (this.FileName),
            Arguments = context.GetValue (this.Arguments),
            WorkingDirectory = context.GetValue (this.WorkingDirectory)
        };

        var env_vars = context.GetValue (this.EnvironmentVariables);
        if (env_vars != null)
        {
            foreach (var v in env_vars)
                psi.EnvironmentVariables.Add (v.Key, v.Value);
        }

        Process.Start (psi);
    }
}

CopyDirectory activity from the Build.Workflow assembly is what you need.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top