我在TFS 2012實例中發生了類似的事情。我的SQL查詢有點不同,因爲TFS 2012的模式發生了變化。希望這可以幫助某人。
SELECT c.[CreationDate], c.[Content], v.FullPath
FROM [dbo].[tbl_Content] c
INNER JOIN [dbo].[tbl_File] f ON f.ResourceId = c.ResourceId
INNER JOIN [dbo].[tbl_PendingChange] pc ON pc.FileId = f.FileId--c.FileId
INNER JOIN [dbo].[tbl_Workspace] w ON w.WorkspaceId = pc.WorkspaceId
INNER JOIN [dbo].[tbl_Version] v ON v.ItemId = pc.ItemId AND v.VersionTo = 2147483647
WHERE w.WorkspaceName = @ShelvesetName
2147483647似乎是2^32 - 1,我認爲可以代表在TFS 2012「最新」後來我也寫了一個C#小部件的解壓gzip編碼流和轉儲到磁盤正確的文件名稱。我不保留層次結構。
string cnstring = string.Format("Server={0};Database={1};Trusted_Connection=True;", txtDbInstance.Text, txtDbName.Text);
SqlConnection cn = new SqlConnection(cnstring);
SqlCommand cmd = new SqlCommand(@"
SELECT c.[CreationDate], c.[Content], v.FullPath
FROM [dbo].[tbl_Content] c
INNER JOIN [dbo].[tbl_File] f ON f.ResourceId = c.ResourceId
INNER JOIN [dbo].[tbl_PendingChange] pc ON pc.FileId = f.FileId--c.FileId
INNER JOIN [dbo].[tbl_Workspace] w ON w.WorkspaceId = pc.WorkspaceId
INNER JOIN [dbo].[tbl_Version] v ON v.ItemId = pc.ItemId AND v.VersionTo = 2147483647
WHERE w.WorkspaceName = @ShelvesetName", cn);
cmd.Parameters.AddWithValue("@ShelvesetName", txtShelvesetName.Text);
DataTable dt = new DataTable();
new SqlDataAdapter(cmd).Fill(dt);
listBox1.DisplayMember = "FullPath";
listBox1.ValueMember = "FullPath";
listBox1.DataSource = dt;
if(!Directory.Exists(txtOutputLocation.Text)) { Directory.CreateDirectory(txtOutputLocation.Text); }
foreach (DataRow row in dt.Rows)
{
string[] arrFilePath = row[2].ToString().Split('\\');
string fileName = arrFilePath[arrFilePath.Length - 2];
byte[] unzippedContent = Decompress((byte[])row[1]);
File.WriteAllBytes(Path.Combine(txtOutputLocation.Text, fileName), unzippedContent);
}
}
static byte[] Decompress(byte[] gzip)
{
using(GZipStream stream = new GZipStream(new MemoryStream(gzip), CompressionMode.Decompress))
{
const int size = 4096;
byte[] buffer = new byte[size];
using(MemoryStream memory = new MemoryStream())
{
int count = 0;
do
{
count = stream.Read(buffer, 0, size);
if(count > 0)
{
memory.Write(buffer, 0, count);
}
}
while(count > 0);
return memory.ToArray();
}
}
}
同樣的情況,但對於TFS2015。我發佈瞭解決方案http://stackoverflow.com/questions/42233302/tfs2015-how-can-i-recover-shelved-changes –