我有一个用 c# 编写的自定义签入策略,并且我使用了 VSIX 项目,并在安装时启用了自定义操作。安装效果很好。如果我将自定义签入策略应用于 TFS 2010 中的团队项目,并且我从同一个安装程序中卸载了我的策略,它正在清理注册表和文件,但源代码管理仍然启用了该策略并引发错误加载错误政策。我希望我的安装程序在卸载策略时从源代码管理中删除该策略。我怎样才能做到这一点?
我试图在 OnAfterUninstall 事件中编写以下代码,但它没有做我需要的事情:
protected override void OnAfterUninstall(IDictionary savedState)
{
base.OnAfterUninstall(savedState);
RemovePolicy();
}
private void RemovePolicy()
{
try
{
TfsTeamProjectCollection projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(projectCollectionUri, new UICredentialsProvider());
projectCollection.EnsureAuthenticated();
VersionControlServer vcs = projectCollection.GetService<VersionControlServer>();
List<TeamProject> lstTeamProject = vcs.GetAllTeamProjects(true).ToList<TeamProject>();
foreach (TeamProject tp in lstTeamProject)
{
List<PolicyEnvelope> tc = tp.GetCheckinPolicies().ToList<PolicyEnvelope>();
var myPolicy = new MyCustomCheckinPolicy();
TeamProject teamProject = vcs.GetTeamProject(tp.Name);
foreach (PolicyType policyType in Workstation.Current.InstalledPolicyTypes)
{
if (policyType.Name == myPolicy.Type)
{
tc.Remove(new PolicyEnvelope(myPolicy, policyType));
teamProject.SetCheckinPolicies(tc.ToArray());
break;
}
}
}
}
catch (Exception ex)
{
throw new InstallException("My Error Message");
}
}