![](/img/trans.png)
[英]Visual Studio VSPackage / Single File Generator - Log Message to Error List
[英]How to checkout a file in TFS in Visual Studio Single File Generator?
我正在為VS 2013編寫VS單個文件生成器。在生成器中,我試圖在父文件夾中創建/修改新文件。 如果我要創建的文件已經存在並且是只讀的(在TFS中由源代碼控制),則在嘗試向其中寫入任何內容時出現錯誤。
我想我需要以編程方式檢出文件,然后再進行編輯。 有人可以提供任何有關如何實現的建議嗎?
我還將這個新文件添加到項目文件中,我相信我也必須先簽出項目文件,然后才能添加到項目文件中。
我通過檢查正在修改的文件是否在源代碼管理中來解決它。 如果它在源代碼管理中並且沒有簽出,那么我會在嘗試修改文件之前簽出該文件。 我創建了一個下面的方法,其中dte
是EnvDTE.DTE
。
private void CheckoutFileIfRequired(string fileName)
{
if (dte.SourceControl == null
|| !dte.SourceControl.IsItemUnderSCC(fileName)
|| dte.SourceControl.IsItemCheckedOut(fileName))
{
return;
}
Action<string> checkOutAction;
checkOutAction = file => dte.SourceControl.CheckOutItem(file);
// run on worker thread to prevent the tool calling back into VS
checkOutAction.EndInvoke(checkOutAction.BeginInvoke(fileName, null, null));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.