我有一个自定义的TFS构建过程,用于我的Web应用程序项目,该过程也进行发布。为了实现这一点,我试图从构建中复制编译的源代码之前删除当前的发布位置。删除TFS 2010期间的app_offline构建
这可以工作(大部分时间),除非文件因为有人访问网站而被锁定,通常不是问题,因为大多数时候构建都是在没有人访问时发生的(因为这些都是纯开发和QA构建)。
要尝试修复无法删除发布目录的边缘情况,我将app_offline.htm文件复制到该目录,并等待4秒钟后再尝试删除网站的其余部分。这工作,但我没有从这一步得到任何错误,但是,当我尝试删除发布完成后的app_offline.htm。我收到以下错误:
Cannot cancel the workflow. Agent needs to be restarted. Details: The operation could not be performed because WorkflowApplication f670d4fb-d9e3-4f33-bc3d-925faa925e04 is aborted.
删除是使用自定义的CodeActivity创建的(因为TFS工作流没有删除)。
public sealed class DeleteFile : CodeActivity
{
// Define an activity input argument of type string
[RequiredArgument]
public InArgument<string> File { get; set; }
public InArgument<int?> Tries { get; set; }
// If your activity returns a value, derive from CodeActivity<TResult>
// and return the value from the Execute method.
protected override void Execute(CodeActivityContext context)
{
// Obtain the runtime value of the Text input argument
int tries = Tries.Get(context) ?? 1;
for (int i = 0; i < tries; i++)
{
try
{
System.IO.File.Delete(File.Get(context));
break;
}
catch (System.IO.IOException)
{
if (i == tries - 1)
throw;
Thread.Sleep(TimeSpan.FromSeconds(4));
}
}
}
}
我后来添加了“尝试”参数,试图捕获是什么导致了这个错误。
但是,值得注意的是,在查看日志时,上述错误不在DeleteFile活动下,而只在日志顶部,没有其他错误或警告。
最后,我们tfsbuild用户删除发布目录的权限(它有没有问题,删除该目录的其余部分只是app_offline.htm