以编程方式将文件检查到 TFS 中的次数超出预期 [英] Programatically checking files into TFS getting more than expected

查看:19
本文介绍了以编程方式将文件检查到 TFS 中的次数超出预期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


所以我有一个 .NET 应用程序,它通过并生成一系列文件,将它们输出到本地目录,然后确定它是否需要更新现有文件或将新文件添加到 TFS(团队基础服务器)项目中.
我的本地机器上有一个工作区,有 10 个不同的工作文件夹,这些文件夹是我在这台特定机器上处理过的其他编码项目.当我去检查该文件是否已存在于 TFS 项目中并且需要更新或者是否需要将其作为新文件添加到项目时,就会出现我的问题.
片段:

<前>静态字符串 TFSProject = @"$/SQLScripts/";静态 WorkspaceInfo wsInfo;静态 VersionControlServer 版本控制;静态字符串 argPath = "E:\\SQLScripts\\";wsInfo = Workstation.Current.GetLocalWorkspaceInfo(argPath);TeamFoundationServer tfs = new TeamFoundationServer(wsInfo.ServerUri.AbsoluteUri);versionControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));工作区工作区 = versionControl.GetWorkspace(wsInfo);workspace.GetLocalItemForServerItem(TFSProject);


在这一点上,我检查文件是否存在,然后我做两件事之一.如果文件存在,那么我将文件标记为 EDIT,然后将文件写出到本地目录,否则我将首先编写文件脚本,然后将文件添加到工作区.我不在乎物理文件是否与我生成的文件相同,因为我这样做是作为 SAS70 要求跟踪更改"

如果它存在,我会这样做:
工作空间.PendEdit(文件名,RecurisionType.Full);
脚本输出文件(文件名);

或者如果它不存在
脚本输出文件名(文件名);
工作空间.PendAdd(文件名,真);

好的,所有这些都是为了解决问题.当我根据 PROJECT 检查挂起的更改时,我会获得工作区中本地计算机上所有项目的所有挂起更改.

<前>//显示我们待处理的更改.PendingChange[] pendingChanges = workspace.GetPendingChanges();foreach(pendingChanges 中的 PendingChange pendingChange){做点什么...}

我认为通过将工作区设置为workspace.GetLocalItemForServerItem(TFSProject),它只会给我那个特定工作文件夹的对象.

是否有什么办法可以强制工作区对象只处理特定的工作文件夹?

这有意义吗?提前致谢...

解决方案

好吧,原来我的机器上有一个损坏的 TFS 工作区缓存.这是解决方案(来自命令提示符):

<前>SET AppDataTF=%USERPROFILE%\Local Settings\Application Data\Microsoft\Team FoundationSET AppDataVS=%APPDATA%\Microsoft\VisualStudio如果存在 "%AppDataTF%\1.0\Cache" rd/s/q "%AppDataTF%\1.0\Cache" > NUL如果存在 "%AppDataTF%\2.0\Cache" rd/s/q "%AppDataTF%\2.0\Cache" > NUL如果存在 "%AppDataVS%\8.0\Team Explorer" rd/s/q "%AppDataVS%\8.0\Team Explorer" > NUL如果存在 "%AppDataVS%\9.0\Team Explorer" rd/s/q "%AppDataVS%\9.0\Team Explorer" > NUL

问题的另一部分是,通过将项目文件夹放在同一个工作区中,它将从其他项目中提取所有待处理的更改.我创建了一个只有 SQLScripts 项目和本地文件夹的辅助工作区,一切都像魅力一样.

也许其他人会觉得这很有用...


So I have a .NET app which goes thru and generates a series of files, outputs them to a local directory and then determines if it needs to update an existing file or add a new file into a TFS (Team Foundation Server) project.
I have a single workspace on my local machine and there are 10 different working folders that are other coding projects I have worked on from this particular machine. My problem happens when I go to check if the file already exists in the TFS project and an update is required or if needs to be added to the project as a new file.
snipet:

static string TFSProject = @"$/SQLScripts/";
static WorkspaceInfo wsInfo;
static VersionControlServer versionControl;
static string argPath = "E:\\SQLScripts\\";

wsInfo = Workstation.Current.GetLocalWorkspaceInfo(argPath);
TeamFoundationServer tfs = new TeamFoundationServer(wsInfo.ServerUri.AbsoluteUri);
versionControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

Workspace workspace = versionControl.GetWorkspace(wsInfo);
workspace.GetLocalItemForServerItem(TFSProject);


At this point I check if the file exists and I do one of two things. if the file exists, then I mark the file for EDIT and then I writeout the file to the local directory, otherwise I will script the file first and then ADD the file to the workspace. I dont care if the physical file is identical to the one I am generating as I am doing this as a SAS70 requirement to 'track changes'

If it exists I do:
workspace.PendEdit(filename,RecurisionType.Full);
scriptoutthefile(filename);

or if it doesn't exist
scriptoutthefilename(filename);
workspace.PendAdd(filename,true);

Ok, all of that to get to the problem. When I go to check on pending changes against the PROJECT I get all the pending changes for all of the projects I have on my local machine in the workspace.

// Show our pending changes. 
PendingChange[] pendingChanges = workspace.GetPendingChanges();
foreach (PendingChange pendingChange in pendingChanges)
{
    dosomething...
}

I thought that by setting the workspace to workspace.GetLocalItemForServerItem(TFSProject) that it would give me ONLY the objects for that particular working folder.

If there any way to force the workspace object to only deal with a particular working folder?

Did that make any sense? Thanks in advance...

解决方案

Ok, so it turned out that I had a corrupted TFS workspace cache on my machine. Here was the solution (from a command prompt):

SET AppDataTF=%USERPROFILE%\Local Settings\Application Data\Microsoft\Team Foundation
SET AppDataVS=%APPDATA%\Microsoft\VisualStudio
IF EXIST "%AppDataTF%\1.0\Cache" rd /s /q "%AppDataTF%\1.0\Cache" > NUL
IF EXIST "%AppDataTF%\2.0\Cache" rd /s /q "%AppDataTF%\2.0\Cache" > NUL
IF EXIST "%AppDataVS%\8.0\Team Explorer" rd /s /q "%AppDataVS%\8.0\Team Explorer" > NUL
IF EXIST "%AppDataVS%\9.0\Team Explorer" rd /s /q "%AppDataVS%\9.0\Team Explorer" > NUL

The other part of the issue is that by having the project folder in the same workspace, it WILL pull in all pending changes from other projects. I created a secondary workspace with only the SQLScripts project and local folder and everything works like a charm.

Maybe someone else will find this useful...

这篇关于以编程方式将文件检查到 TFS 中的次数超出预期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆