【发布时间】: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