【问题标题】:How to remove the custom checkin policy while uninstalling?卸载时如何删除自定义签入策略?
【发布时间】:2013-02-05 15:59:02
【问题描述】:

我有一个用 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");
        }
    }

【问题讨论】:

  • 那么它在做什么?它会抛出错误,惨遭失败吗?你真的确定要这样做吗?任何删除策略的团队成员都会将其从服务器中删除!
  • Any team member removing the policy will remove it from the server! 哎呀,我不知道。在那种情况下,我不想这样做。谢谢你警告我。

标签: tfs tfs-sdk checkin-policy


【解决方案1】:

由于需要在访问 TFS 项目的所有开发人员工作站上安装自定义签入策略,因此在卸载时将其从 TFS 项目中注销实际上会在这些开发人员中的任何一个卸载时删除该策略它。我怀疑这不是你想要的。

有很多方法可以ensure the policy is distributed to all team members through the Team Foundation Power Tools,这样,如果您需要发布升级或不同的政策,您将确保所有成员都拥有它。只能通过 UI 手动取消注册。

【讨论】:

    猜你喜欢
    • 2013-11-07
    • 1970-01-01
    • 2023-03-26
    • 2011-10-04
    • 2020-01-20
    • 1970-01-01
    • 1970-01-01
    • 2011-09-02
    • 1970-01-01
    相关资源
    最近更新 更多