{"id":2733,"date":"2007-03-01T21:28:15","date_gmt":"2007-03-01T21:28:15","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/buckh\/2007\/03\/01\/how-to-enable-a-checkin-policy-via-the-version-control-api\/"},"modified":"2007-03-01T21:28:15","modified_gmt":"2007-03-01T21:28:15","slug":"how-to-enable-a-checkin-policy-via-the-version-control-api","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/buckh\/how-to-enable-a-checkin-policy-via-the-version-control-api\/","title":{"rendered":"How to enable a checkin policy via the version control API"},"content":{"rendered":"<p>I recently needed to test a new checkin policy that I wrote.&nbsp; In order to do that, I needed to enable a checkin policy for the unit test&#8217;s team project using the version control API.&nbsp; I was a little surprised when it wasn&#8217;t quite as obvious as I had hoped, and I had to poke around in the source to figure it out.&nbsp; So, I thought I&#8217;d post the code snippet.<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using Microsoft.TeamFoundation.TeamFoundation.Client;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using Microsoft.TeamFoundation.VersionControl.Client;<\/p>\n<p><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TeamFoundationServer tfs = new TeamFoundationServer(http:\/\/yourserver:8080);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VersionControlServer vcs = (VersionControlServer) tfs.GetService(typeof(VersionControlServer));<\/p>\n<p><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TeamProject tp = vcs.GetTeamProject(&#8220;SomeTeamProject&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MyCustomPolicy customPolicy = <span style=\"color: #0000ff\">new<\/span> MyCustomPolicy();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: #0000ff\">bool<\/span> foundPolicy = <span style=\"color: #0000ff\">false<\/span>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: #0000ff\">foreach<\/span> (PolicyType policyType <span style=\"color: #0000ff\">in<\/span> Workstation.Current.InstalledPolicyTypes)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: #0000ff\">if<\/span> (policyType.Name == customPolicy.Type)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tp.SetCheckinPolicies(<span style=\"color: #0000ff\">new<\/span> PolicyEnvelope[] { <span style=\"color: #0000ff\">new<\/span> PolicyEnvelope(customPolicy, policyType) });<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foundCustomPolicy = <span style=\"color: #0000ff\">true<\/span>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: #0000ff\">break<\/span>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!foundCustomPolicy)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new ApplicationException(&#8220;<span style=\"color: #8b0000\">Something&#8217;s wrong &#8212; MyCustomPolicy is not installed<\/span>&#8220;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/p>\n<p>tags: <a href=\"http:\/\/technorati.com\/tag\/tfs\" rel=\"tag\">tfs<\/a>, <a href=\"http:\/\/technorati.com\/tag\/team+foundation\" rel=\"tag\">team foundation<\/a>, <a href=\"http:\/\/technorati.com\/tag\/version+control\" rel=\"tag\">version control<\/a>, <a href=\"http:\/\/technorati.com\/tag\/checkin+policy\" rel=\"tag\">checkin policy<\/a><\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently needed to test a new checkin policy that I wrote.&nbsp; In order to do that, I needed to enable a checkin policy for the unit test&#8217;s team project using the version control API.&nbsp; I was a little surprised when it wasn&#8217;t quite as obvious as I had hoped, and I had to poke [&hellip;]<\/p>\n","protected":false},"author":94,"featured_media":10268,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[6,8,15],"class_list":["post-2733","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-source-control","tag-team-foundation","tag-tfs-api"],"acf":[],"blog_post_summary":"<p>I recently needed to test a new checkin policy that I wrote.&nbsp; In order to do that, I needed to enable a checkin policy for the unit test&#8217;s team project using the version control API.&nbsp; I was a little surprised when it wasn&#8217;t quite as obvious as I had hoped, and I had to poke [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/posts\/2733","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/users\/94"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/comments?post=2733"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/posts\/2733\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/media\/10268"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/media?parent=2733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/categories?post=2733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/tags?post=2733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}