我有一个 VS2010 开发的实用程序,可以进行 TFS 工作项查询和检查,我只能在已经安装了 VS2010 的机器上使用它(我认为 Team Explorer 2010 应该是真正需要的那个)。
现在我们已经在客户端迁移到VS2019,因为VS2010很旧而且有bug,但是TFS服务器仍然是2010,迁移起来并不容易,因为上面的数据太多了。
问题来了,希望工具能更新一下,支持在只装VS2019的机器上运行。反正VS2019可以自己访问TFS2010,如果我可以用VS2019开发,为什么不使用实用程序呢?
首先,我相信我的代码应该能够连接到 TFS 2010:
using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
TfsTeamProjectCollection collection = new TfsTeamProjectCollection(new Uri(@"http://tfs:8080/tfs/DefaultCollection"));
}
}
}
它编译顺利,然后当我运行它时它给了我这些:
Unhandled exception. System.EntryPointNotFoundException: Unable to find an entry point named 'ZeroMemory' in DLL 'kernel32.dll'.
at Microsoft.VisualStudio.Services.Common.Internal.NativeMethods.ZeroMemory(IntPtr address, UInt32 byteCount)
at Microsoft.VisualStudio.Services.Common.CredentialsCacheManager.GetCredentialsFromStore(String targetName)
at Microsoft.VisualStudio.Services.Common.CredentialsCacheManager.GetCredentials(String featureRegistryKeyword, String targetName)
at Microsoft.VisualStudio.Services.Common.CredentialsCacheManager.GetCredentials(String featureRegistryKeyword, Uri uri, Boolean requireExactUriMatch, Nullable`1 nonInteractive)
at Microsoft.VisualStudio.Services.Client.VssClientCredentials.LoadCachedCredentials(String featureRegistryKeyword, Uri serverUrl, Boolean requireExactMatch, CredentialPromptType promptType)
at Microsoft.VisualStudio.Services.Client.VssClientCredentials.LoadCachedCredentials(Uri serverUrl, Boolean requireExactMatch, CredentialPromptType promptType)
at Microsoft.TeamFoundation.Client.TfsConnection.LoadFromCache(Uri serverUrl, ICredentials credentials)
at Microsoft.TeamFoundation.Client.TfsConnection..ctor(Uri uri, String locationServiceRelativePath, IdentityDescriptor identityToImpersonate, ITfsRequestChannelFactory channelFactory)
at Microsoft.TeamFoundation.Client.TfsConnection..ctor(Uri uri, String locationServiceRelativePath)
at Microsoft.TeamFoundation.Client.TfsTeamProjectCollection..ctor(Uri uri, Boolean fromFactory)
at Microsoft.TeamFoundation.Client.TfsTeamProjectCollection..ctor(Uri uri)
at ConsoleApp2.Program.Main(String[] args) in D:\Code\ConsoleApp2\ConsoleApp2\Program.cs:line 11
D:\Code\ConsoleApp2\ConsoleApp2\bin\Debug\net5.0\ConsoleApp2.exe (process 22888) exited with code -532462766.
Press any key to close this window . . .
为了使构建成功,我在
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\TestTools\TeamExplorerClient
下添加了对dll的引用:
基本上,我不知道接下来我能做什么,任何意见或建议将不胜感激。
看起来你的目标是 .NET 5,大多数 TFS 客户端对象模型还没有准备好在 .NET Core 和 .NET 5+ 下运行。尝试将您的应用程序创建为 .NET 4.7.2 应用程序,然后重试。尤其是旧的 Work Item Tracking 代码依赖于一组尚未移植的本机库和 SOAP 服务。 Azure DevOps Server 现在使用 REST API 来处理其中的大部分请求。
而不是直接从 visual studio 安装文件夹引用程序集,而是尝试添加对官方 nuget 包的引用:
Microsoft.TeamFoundationServer.ExtendedClient
注意:我不是 100% 确定最新版本的 nuget 是否可以工作,因为 TFS 2010 不再支持,但您可以根据需要添加旧版本。
PS:即使您的TFS 2010 服务器很大并且包含大量数据,也要考虑该数据的安全性和完整性。 TFS 仅在 不受支持的 Windows Server 操作系统版本 上运行,针对 不受支持的 SQL Server 版本 并且 本身不再打补丁、更新和保持安全。如果你重视你的源代码,我怀疑你这样做,那么迁移到 Azure DevOps Server 或 Azure DevOps Cloud 是 highly recommended.