如何在不依赖 Visual Studio 版本的情况下使用 C# 从 TFS 检出文件?

How to Checkout Files From TFS using C# Without Being dependent on Visual Studio Version?

我有一个生成一些代码文件的应用程序。我可以选择使用这段代码从 TFS 检出文件:

private void CheckoutFile(string fileName)
{
    var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(fileName);
    var server = new TfsTeamProjectCollection(workspaceInfo.ServerUri);
    var workspace = workspaceInfo.GetWorkspace(server);

    workspace.PendEdit(fileName);
}

它对我来说很好用,我的机器上安装了 VS 2013。我的一位同事只有 VS 2012,但出现以下错误:

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.Services.Common, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

我需要做什么才能使 checkout VS 版本独立?

更新

显然是我的同事误会了。他将 VS2013 dll 放在错误的文件夹中。现在它位于正确的文件夹中,CheckoutFile 中调用的方法之一返回 null... 还不太确定是哪个。

似乎指出该项目缺少程序集引用或 using 语句,但这可能是因为它不支持该项目的某些部分。我建议您的同事开始使用 Visual Studio 社区,或者您尝试寻找 Services.Common 的替代品。

如果不是,可能是您与正在引用的文件的连接有问题?

无法独立调用 API 版本。您需要确保您的用户拥有相同的版本,或者为每个应用程序提供特定的版本。

然而,您可以调用 tf.exe 而不依赖于版本。

在您的解决方案中,在项目引用下,针对 TFS 库,取消选中 "specific version" and/or 考虑选中 "copy local" 一个。