我有一個自定義的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