Team Foundation Server, Check out file without Workspace
I have TFS url, and I have source File location, but I don’t have Workspace path. How to Check out file without workspace, or how to find workspace for some file?
I already make solution for checkout file in TFS, but in some cases I don’t have workspace path or name.
Dim TeamFoundationServerURL As String ="TFS url"
Dim TeamProjectCollection As TfsTeamProjectCollection
'Get project collectio
TeamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection( _
New Uri(TeamFoundationServerURL), New UICredentialsProvider())
TeamProjectCollection.EnsureAuthenticated()
Dim Workspace As Workspace
' get Version Co开发者_StackOverflow中文版ntrol
Dim VersionControlServer As VersionControlServer
VersionControlServer = TeamProjectCollection.GetService(Of VersionControlServer)()
'location to check out files to:
Dim WorkspacePath As String = "__I dot have this path ___"
'find workspace
Workspace = VersionControlServer.GetWorkspace(WorkspacePath)
'Check out file
Workspace.PendEdit(SorceFilePath)
Thanks
Check out without a workspace is not possible. So if you need to check out and don't have any workspace information - you should create a wokspace on demand. There's also an option to get file downloaded without a workspace VersionControlServer.DownloadFile. See http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.versioncontrolserver.downloadfile(v=vs.80).aspx for details. It will not be checked out though (like "view" console command).
I wanted to do this with my autobuild. I had it checking out a version file and then checking it back in (after updating it). Since this was the build machine I did not have a work space mappings that I could guarantee.
I ended up just checking to see if the file I needed was mapped. If it was not then I would map it.
I know that is not the solution you were looking for, but I thought I would throw it out there for you to consider.
Here is my code that does the checking out and checking in:
private Version GetVersionFromTFS(Workspace currentWorkspace, string versionFileLocation, string versionFileName, out string localVersionPath)
{
// Make sure we have a map to the version file
if (!currentWorkspace.IsServerPathMapped(versionFileLocation))
{
// Map the version file to somewhere.
currentWorkspace.Map(versionFileLocation, @"C:\temp\BuildVersions" + Guid.NewGuid());
}
// Make sure we have the latest from source control.
GetRequest getRequest = new GetRequest(new ItemSpec(versionFileLocation + versionFileName,RecursionType.None), VersionSpec.Latest);
currentWorkspace.Get(getRequest, GetOptions.Overwrite);
localVersionPath = currentWorkspace.GetLocalItemForServerItem(versionFileLocation + versionFileName);
string oldVersion = "1.0.0.0";
if (File.Exists(localVersionPath))
oldVersion = File.ReadAllText(localVersionPath);
return new Version(oldVersion);
}
private void UpdateVersionBackToTFS(Workspace currentWorkspace, string versionFileLocation, string versionFileName, Version newVersion, String localVersionPath)
{
File.WriteAllText(localVersionPath, newVersion.ToString());
WorkspaceCheckInParameters parameters = new WorkspaceCheckInParameters(new[] {new ItemSpec(versionFileLocation + versionFileName, RecursionType.None)}, "***NO_CI*** - Updating Version" );
currentWorkspace.CheckIn(parameters);
}
精彩评论