I have a custom checkin policy written in c# and I used VSIX project with custom action enabled on install. Installation is working great. If I have the custom checkin policy applied to the team project in TFS 2010 and I uninstalled my policy from the same installer, it is cleaning up the registry and the files, but the source control still have the policy enabled and throws an error Error loading the policy. I want my installer to remove the policy from the source control while uninstalling the policy. How can I achieve this?
I tried to write the following code in OnAfterUninstall event, but it is not doing what I need:
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");
}
}