Microsoft.TeamFoundation.VersionControl.Client.Workspace.PendAdd
出于某种原因,每当我从 TFS API 调用 PendAdd 方法时,它都会毫无例外地执行,但无法将任何文件标记为已添加到我的工作区中。但是,调用 PendEdit 始终按预期工作。我已验证所使用的帐户都具有在 TFS 中添加的权限,并且具有对相关文件的完全控制 Windows 权限。
有任何想法吗?
我的代码(为了调试,我尝试对 PendAdd 方法的输入进行四种变体):
public bool AddFile( string filePath, out string status, bool isRecursive = false )
{
Workspace workspace = GetWorkspace( out status );
if( workspace == null )
{
return false;
}
workspace.PendAdd( filePath, isRecursive );
status = "Success";
return true;
}
public bool CheckOutFile( string filePath, out string status )
{
Workspace workspace = GetWorkspace( out status );
if( workspace == null )
{
return false;
}
workspace.PendEdit( filePath );
status = "Success";
return true;
}
...
string status;
// $/Solution/.../foo.cs (non-recursive)
if( TFS.AddFile("$/Solution" + Regex.Split(target, "Solution")[1].Replace('\\', '/'), out status) == false )
{
throw new Exception( "TFS Add failed: " + status );
}
// $/Solution/.../ (recursive)
if( TFS.AddFile("$/Solution" + Regex.Split(target.Substring(0, target.LastIndexOf('\\')), "Solution")[1].Replace('\\', '/'), out status, true) == false )
{
throw new Exception( "TFS Add failed: " + status );
}
// Calls PendEdit with C:\TFS\Solution\...\foo.cs; this works
if( TFS.CheckOutFile(target, out status) == false )
{
throw new Exception( "TFS Checkout failed: " + status );
}
// C:\TFS\Solution\...\foo.cs (non-recursive)
if( TFS.AddFile(target, out status) == false )
{
throw new Exception( "TFS Add failed: " + status );
}
// C:\TFS\Solution\...\ (recursive)
if( TFS.AddFile(target.Substring(0, target.LastIndexOf('\\')), out status, true) == false )
{
throw new Exception( "TFS Add failed: " + status );
}
...
private Workspace GetWorkspace( out string status )
{
Workspace[] workspaces = _versionControlServer.QueryWorkspaces( null, _versionControlServer.AuthorizedUser, Environment.MachineName );
if( workspaces.Length != 1 )
{
status = "You must have exactly 1 local workspace to promote code.";
return null;
}
else
{
status = "You have exactly 1 local workspace.";
}
return workspaces[0];
}