0

我在 Visual Studio 2010 中为 TFS 2010 创建了一个自定义签入策略。该策略本身运行良好。现在,我正在尝试从代码中应用自定义策略。下面是我的代码:

try
        {
            var projectCollectionUri = new Uri("https://mydomain.com/tfs");
            var projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(projectCollectionUri, new UICredentialsProvider());
            projectCollection.EnsureAuthenticated();

            var vcs = projectCollection.GetService<VersionControlServer>();

            var teamProject = vcs.GetTeamProject("myProject");

            foreach (PolicyType policyType in Workstation.Current.InstalledPolicyTypes)
            {
                if (policyType.Name.ToLower().Contains("MyPolicyType"))
                {
                    //teamProject.SetCheckinPolicies(new PolicyEnvelope[] { new PolicyEnvelope(workItemPolicy, policyType) });
                    //break;
                }
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

我被困在这条线上:

//teamProject.SetCheckinPolicies(new PolicyEnvelope[] { new PolicyEnvelope(workItemPolicy, policyType) });

如何为我的自定义策略创建策略信封?我引用的代码来自以下位置: http ://bartwullems.blogspot.com/2012/02/team-foundation-server-2010-enable.html

4

1 回答 1

1

您只需WorkItemPolicy将示例中的 替换为您的策略:

例如:

var myPolicy = new MyPolicy();

foreach (PolicyType policyType in Workstation.Current.InstalledPolicyTypes)
{
    if (policyType.Name == myPolicy.Type)
    {
        teamProject.SetCheckinPolicies(
            new PolicyEnvelope[]
            {
                new PolicyEnvelope(myPolicy, policyType)
            });
        break;
    }
}

如果您的控制台应用程序中没有包含您的策略的程序集,您可能需要添加对它的引用。

于 2013-02-19T20:33:57.460 回答