我的 Web 应用程序项目有一个自定义 TFS 构建过程,它也进行发布。为了实现这一点,我尝试在从构建中复制已编译的源之前删除当前的发布位置。
这有效(大部分时间),除非文件被锁定,因为有人访问该站点,这通常不是问题,因为大多数时候构建发生在没有人访问它们的情况下(因为这些纯粹是开发和 QA 构建) .
为了尝试修复无法删除发布目录的边缘情况,我将 app_offline.htm 文件复制到该目录并等待 4 秒,然后再尝试删除站点的其余部分。这可行,但是,当我在发布完成后尝试删除 app_offline.htm 时,这一步我没有收到任何错误。我收到以下错误:
无法取消工作流。代理需要重新启动。详细信息:无法执行操作,因为 WorkflowApplication f670d4fb-d9e3-4f33-bc3d-925faa925e04 已中止。
删除是使用自定义 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));
}
}
}
}
稍后我添加了“Tries”参数以尝试捕获导致此错误的原因。
不过需要注意的是,查看日志时,上面的错误并没有放在DeleteFile活动下,而只是在日志的顶部,并没有其他错误或警告。
最后,我们的 tfsbuild 用户对发布目录具有删除权限(删除目录的其余部分没有问题,只是 app_offline.htm