C# 如何办理退房手续&;使用C代码从TFS签入文件?
我正在尝试创建一个窗口窗体应用程序,它可以签出、编辑文件并在TFS中签入文件 我可以用下面的代码来做这些操作。我面临的唯一问题是动态获取C# 如何办理退房手续&;使用C代码从TFS签入文件?,c#,tfs,visual-studio-2017,C#,Tfs,Visual Studio 2017,我正在尝试创建一个窗口窗体应用程序,它可以签出、编辑文件并在TFS中签入文件 我可以用下面的代码来做这些操作。我面临的唯一问题是动态获取tf.exe路径。我不希望在解决方案中对tf.exe的路径进行硬编码。我试图打开的tf.exe位于Visual Studio 2017文件夹中 foreach (string path in FilePaths) { var proc = new Process { StartInfo = new ProcessStartInfo {
tf.exe
路径。我不希望在解决方案中对tf.exe
的路径进行硬编码。我试图打开的tf.exe
位于Visual Studio 2017文件夹中
foreach (string path in FilePaths)
{
var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = @"C:\Program Files (x86)\Microsoft Visual Studio
14.0\Common7\IDE\tf.exe",
Arguments = "checkout " + path,
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
proc.Start();
}
应动态获取文件名中提供的路径。您有几个选项: 1) 添加一个函数,用于检查安装位置
tf.exe
,并返回位置(有点难看,当发布新的VS版本时,您需要更新该函数):
2) 要求用户输入位置或他拥有的VS版本并生成版本(在第二个选项中,还需要使用每个新VS版本更新代码):
创建一个新的文本框,给出一个名称(例如:tfextextbox
),在代码中获取值:
string tfExeLoacation = tfExeTxtBox.Text;
3) 使用TFS DLL执行操作,而不是启动tf.exe
进程:
您需要2个DLL(在NuGet中提供):
现在您可以执行所有TFVC操作,例如:
TfsTeamProjectcollection tfs = new TfsTeamProjectColletion(new Uri("tfs-server-url"));
VersionControlServer versionControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
Workspace workspace = versionControl.CreateWorkspace("newWorkSpace", "user name");
// Add to pending changes
workspace.PendAdd("workspace path");
var changes = workspace.GetPendingChanges();
// Check In
workspace.CheckIn(changes, "comment");
您只需向应用程序添加设置,并使用open file dialog对其进行配置。顺便说一句,您可以说VS2017(版本15.x),但可以从以前的VS2015(14.x)中打开
tf.exe
,请参阅。另外,VS安装应该有许多注册表项,请尝试搜索一个返回所需路径的注册表项。
Microsoft.TeamFoundation.Client
Microsoft.TeamFoundation.VersionControl.Client
TfsTeamProjectcollection tfs = new TfsTeamProjectColletion(new Uri("tfs-server-url"));
VersionControlServer versionControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
Workspace workspace = versionControl.CreateWorkspace("newWorkSpace", "user name");
// Add to pending changes
workspace.PendAdd("workspace path");
var changes = workspace.GetPendingChanges();
// Check In
workspace.CheckIn(changes, "comment");