How to delete team project folder from source control? - c#

I created folder with VersionControlServer.CreateTeamProjectFolder:
var connection = new TfsTeamProjectCollection(new Uri("http://my-tfs-serv:8080/tfs/DefaultCollection"));
var vcs = connection.GetService<VersionControlServer>();
vcs.CreateTeamProjectFolder(new TeamProjectFolderOptions("TestFolder"));
That call has created folder $/TestFolder/, now I want to delete it.
I could not find API for that. I tried to remove it with
TFSDeleteProject.exe /force /collection:http://my-tfs-serv:8080/tfs/DefaultCollection TestFolder
But it returns:
TF200016: The following project does not exist: TestFolder. Verify that the name of the project is correct and that the project exists on the specified Team Foundation Server.
Looks like VersionControlServer.CreateTeamProjectFolder() does not create a team project, it just creates the folder only.
But how can i remove that folder now?

TFSDeleteProject cmd won't work on items created with the code you are using. You can use the following code to delete(destroy):
var itemSpec = new ItemSpec(FullRepositoryPath, RecursionType.Full);
Item[] removedItems = TFSImplementor.VersionControl.Destroy(
itemSpec,
VersionSpec.Latest,
null,
DestroyFlags.StartCleanup);
TFSDeleteProject cmd will only work on projects created from Wizard.

Related

Rename TFS Branch Programaticly c# (TFS2017)

I'm trying to rename a branch programaticly using "PendRename" method from Microsoft.TeamFoundation.VersionControl.Client.
Moves working, so, if I use this to move everything to a new location, it works, but what I need is to rename a branch.
It is possible to do this by commandline "tfs.exe rename " (even this is given me errors if I have more than one workspace mapped for the same server url. the ... could not be found in your workspace, or you do not have permission to access it.)
So, could you please help to understand why rename a branch is not working?
Thank you,
To Rename or move files and folders in TFVC, you must be one of the Contributors for your team project. See Team Foundation Server default groups, permissions, and roles.
I tested that and renamed the branch correctly with the "PendRename" method.
Below code sample for your reference:
using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
namespace RenameBranch
{
class Program
{
static void Main(string[] args)
{
string oldPath = #"E:\andy\0418Scrum\web0418-0823";
string newPath = #"E:\andy\0418Scrum\web0418-1020";
string collection = #"http://server:8080/tfs/DefaultCollection";
var tfsServer = new Uri(collection);
var tpc = new TfsTeamProjectCollection(tfsServer);
var vcs = tpc.GetService<VersionControlServer>();
Workspace workspace = vcs.GetWorkspace("YourWorkspaceName", vcs.AuthorizedUser);
workspace.PendRename(oldPath, newPath);
}
}
}
Then you need CheckIn it of course. Use a "workspace.GetPendingChanges()" and "workspace.CheckIn()" methods to do it.
Thank you,
The problem was, there are different processes that are generating workspaces to the directory, and then, he can't remove it.
So, I solve this issue doing this steps:
1. reserve a workspace local location for my appĀ“
2. see if this workspace is mapped. If yes, I remove it
3. create a workspace to the previous folder in path and create the map
4. get latest
5. rename
Thank you Andy-MSFT for your support.

Get TFS mapped folder of a local sub folder of the solution?

Let's say we have a solution in TFS Source Control which has already been mapped to a local folder SolutionFolder.
We are in a sub folder SubFolder of this SolutionFolder.
How can we write C# code to get the mapped path of this SubFolder?
Use the WorkStation.Current to grab the information for the folder in question:
Import the following namespaces:
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
and then use you can get to the data you want through:
var workspace = Workstation.Current.GetLocalWorkspaceInfo(solutionFolder);
if (workspace != null)
{
var teamProjectUri = workspace.ServerUri;
// var server = TfsConfigurationServerFactory.GetConfigurationServer(teamProjectUri);
var projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(teamProjectUri);
var cssService = projectCollection.GetService<ICommonStructureService4>();
var project = cssService.GetProjectFromName(solutionName);
}
From there you can easily grab the Workspace as well and from there the serverpath: workspace.GetWorkspace().GetServerItemForLocalItem()
To provide credentials, you can use one of the additional overloads that accepts a CredentialsProvider. The default provider is the UICredentialsProvider. Or you can also call server or projectCollection's EnsureAuthenticated.
See also:
https://jessehouwing.net/vsts-tfs-api-auto-detect-connection-details/

How to map workspace and get latest folders in c#

It is my first time to work with TFS and I am not quite familiar how workspace mapping works. I would just like to print the local folder and repository folder when the workspace is mapped, so I would know if the workspace is mapped because I get an exception such as "Object reference not set to an instance of an object."
var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(path);
var server = new TfsTeamProjectCollection(workspaceInfo.ServerUri);
var workspace = workspaceInfo.GetWorkspace(server);
workspace.PendEdit(path);
And is my Get Latest code correct? I mean I would like to get the latest version of a whole folder and this is what I got.
var service = tpc.GetService<VersionControlServer>();
var getLatestOfTfsRepositoryCs = service.GetWorkspace(#"C:\temp\project");
I suggest you to use Workspace.IsLocalPathMapped method in order to check
link : http://msdn.microsoft.com/fr-fr/library/microsoft.teamfoundation.versioncontrol.client.workspace.islocalpathmapped.aspx
If you wish get lastest version you can use Workspace.Get method, with VersionSpec.Latest value

get latest specific project in C#

I have a project that should be get latest to specific date. I have this code:
var serverFolder = pathInTfs;
var localFolder = pathInLocalMachin;
var workingFolder = new WorkingFolder(serverFolder, localFolder);
// Create a workspace mapping
workspace.CreateMapping(workingFolder);
if (!workspace.HasReadPermission)
{
throw new SecurityException(
String.Format("{0} does not have read permission for {1}",
versionControl.AuthorizedUser, serverFolder));
}
// Get the files from the repository
workspace.Get(dateForLatest, GetOptions.Overwrite);
every thing is good but I want to be get latest only directory "pathInTfs" in "pathInLocalMachin" but when program run workspace.Get() every project be get latest.
How I can get latest one path in my project.
There are several overloads of Get which allow you to specify the set of objects you want to get. For what you're doing, I think you want Get(GetRequest, GetOptions).
The GetRequest includes an ItemSpec where you can specify a folder to get, and then indicate RecursionType.Full.

FileVersionInfo doesn't match Details tab in Explorer

I'm attempting to use C# and System.Diagnostics.FileVersionInfo to extract the version information from a list of files. My purpose for doing this is to keep track of unique filepath and version combinations. When the files change I'd like various things to happen depending on what exactly changed.
I've used both the FileVersion and ProductVersion properties of FileVersionInfo to no avail. Both report a different version number than what is reported in explorer.
An example using explorer.exe
Explorer Details tab reports: "6.1.7601.17567" (for both File and Product)
FVI.ProductVersion reports: "6.1.7600.16385"
FVI.FileVersion reports: "6.1.7600.16385 (win7_rtm.090713-1255)"
For some reason the ProductVersion property doesn't match the ProductMajorPart/MinorPart/BuildPart/PrivatePart... To get the actual version you can do this:
var fvi = FileVersionInfo.GetVersionInfo(path);
var productVersion = new Version(
fvi.ProductMajorPart,
fvi.ProductMinorPart,
fvi.ProductBuildPart,
fvi.ProductPrivatePart);
var fileVersion = new Version(
fvi.FileMajorPart,
fvi.FileMinorPart,
fvi.FileBuildPart,
fvi.FilePrivatePart);

Categories

Resources