{"id":10491,"date":"2006-08-28T09:46:00","date_gmt":"2006-08-28T09:46:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/bharry\/2006\/08\/28\/exporting-areas-and-iterations\/"},"modified":"2018-08-14T00:35:01","modified_gmt":"2018-08-14T00:35:01","slug":"exporting-areas-and-iterations","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/bharry\/exporting-areas-and-iterations\/","title":{"rendered":"Exporting Areas and Iterations"},"content":{"rendered":"<p>A couple of days ago someone asked me how to export the areas and iterations from one project and be able to use them as a template to create other projects.&nbsp; Creating a set of pre-defined Areas &amp; Iterations is a feature of the TFS process templates.&nbsp; In this post I&#8217;ve included a sample to show how to export the Areas and Iterations of an existing project into the format required for the Project Creation Wizard to use.<\/p>\n<p>It is a command line tool with usage of the following form:<\/p>\n<p>ExportClassifications \/server:&lt;yourserver&gt; &lt;yourproject&gt;<\/p>\n<p>This will create a file called Classification.xml that contains properly formatted XML for the Project Creation Wizard to use.<\/p>\n<p>The only things that remain&nbsp;are <\/p>\n<ul>\n<li>Export your Process Template using Team -&gt; Team Foundation Server Settings -&gt; Process Template Manager\n<li>Replace your the Classifications\\Classifications.xml with the one generated by ExportClassifications\n<li>Use Process Template Manager to upload the updated Process Template\n<li>Start creating projects<\/li>\n<\/ul>\n<p>I&#8217;ve attached the full sample project and a compiled version of the exe to this post for those who want it.&nbsp; I&#8217;ve also included here the &#8220;heart&#8221; of the code that does the real work if you&#8217;re just intersted in the API mechanics.<\/p>\n<p><font face=\"Courier New\" size=\"2\">&nbsp;&nbsp;&nbsp; \/\/ Connect to the server.<br \/>&nbsp;&nbsp;&nbsp; TeamFoundationServer tfs = new TeamFoundationServer(server);<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">&nbsp;&nbsp;&nbsp; \/\/ Get the common structure interface.<br \/>&nbsp;&nbsp;&nbsp; ICommonStructureService css = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService));<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">&nbsp;&nbsp;&nbsp; \/\/ Get the project we want to operate on.<br \/>&nbsp;&nbsp;&nbsp; ProjectInfo projectInfo = css.GetProjectFromName(project);<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">&nbsp;&nbsp;&nbsp; \/\/ Create the XML document that we are going to write the areas and iterations to.<br \/>&nbsp;&nbsp;&nbsp; XmlDocument doc = new XmlDocument();<br \/>&nbsp;&nbsp;&nbsp; doc.AppendChild(doc.CreateXmlDeclaration(&#8220;1.0&#8221;, &#8220;utf-8&#8221;, null));<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">&nbsp;&nbsp;&nbsp; \/\/ Create the tasks top level node.<br \/>&nbsp;&nbsp;&nbsp; XmlNode parent = doc.CreateNode(XmlNodeType.Element, &#8220;tasks&#8221;, String.Empty);<br \/>&nbsp;&nbsp;&nbsp; doc.AppendChild(parent);<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">&nbsp;&nbsp;&nbsp; \/\/ Create the node for the CommonStructureService task.<br \/>&nbsp;&nbsp;&nbsp; XmlNode child = doc.CreateNode(XmlNodeType.Element, &#8220;task&#8221;, String.Empty);<br \/>&nbsp;&nbsp;&nbsp; AddAttribute(doc, child, &#8220;id&#8221;, &#8220;UploadStructure&#8221;);<br \/>&nbsp;&nbsp;&nbsp; AddAttribute(doc, child, &#8220;name&#8221;, &#8220;Creating project structure&#8221;);<br \/>&nbsp;&nbsp;&nbsp; AddAttribute(doc, child, &#8220;plugin&#8221;, &#8220;Microsoft.ProjectCreationWizard.Classification&#8221;);<br \/>&nbsp;&nbsp;&nbsp; AddAttribute(doc, child, &#8220;completionMessage&#8221;, &#8220;Team project structure created.&#8221;);<br \/>&nbsp;&nbsp;&nbsp; parent.AppendChild(child);<br \/>&nbsp;&nbsp;&nbsp; parent = child;<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">&nbsp;&nbsp;&nbsp; \/\/ Create the node to contain the data for the CommonStructureService task.<br \/>&nbsp;&nbsp;&nbsp; child = doc.CreateNode(XmlNodeType.Element, &#8220;taskXml&#8221;, String.Empty);<br \/>&nbsp;&nbsp;&nbsp; parent.AppendChild(child);<br \/>&nbsp;&nbsp;&nbsp; parent = child;<br \/>&nbsp;&nbsp;&nbsp; XmlNode taskXmlNode = child;<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">&nbsp;&nbsp;&nbsp; \/\/ Create the container for the root level CSS heirarchy nodes.<br \/>&nbsp;&nbsp;&nbsp; child = doc.CreateNode(XmlNodeType.Element, &#8220;Nodes&#8221;, String.Empty);<br \/>&nbsp;&nbsp;&nbsp; parent.AppendChild(child);<br \/>&nbsp;&nbsp;&nbsp; parent = child;<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">&nbsp;&nbsp;&nbsp; \/\/ Get the list of heirarchies from the server.<br \/>&nbsp;&nbsp;&nbsp; NodeInfo[] nodes = css.ListStructures(projectInfo.Uri);<br \/>&nbsp;&nbsp;&nbsp; foreach (NodeInfo node in nodes)<br \/>&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/ Handle the root nodes in the hierarchy specially because they have slightly different<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/ naming and attribute handling.<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String name;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (node.StructureType == &#8220;ProjectModelHierarchy&#8221;)<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name = &#8220;Area&#8221;;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name = &#8220;Iteration&#8221;;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; child = doc.CreateNode(XmlNodeType.Element, &#8220;Node&#8221;, String.Empty);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AddAttribute(doc, child, &#8220;StructureType&#8221;, node.StructureType);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AddAttribute(doc, child, &#8220;Name&#8221;, name);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AddAttribute(doc, child, &#8220;xmlns&#8221;, String.Empty);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; parent.AppendChild(child);<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/ Get the XML for this CSS Hierarchy.<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XmlElement parentXmlNode = css.GetNodesXml(new String[] { node.Uri }, true);<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/ Skip down the hierarchy past the root node (which contains the same data as in the<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/ NodeInfo that we got with ListStructures).<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XmlNode inNode = parentXmlNode.ChildNodes[0];<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (inNode.ChildNodes.Count &gt; 0)<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inNode = inNode.ChildNodes[0];<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WriteNodes(doc, child, inNode.ChildNodes);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp; }<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">&nbsp;&nbsp;&nbsp; \/\/ Write the reference to the project mapping file.<br \/>&nbsp;&nbsp;&nbsp; child = doc.CreateNode(XmlNodeType.Element, &#8220;properties&#8221;, String.Empty);<br \/>&nbsp;&nbsp;&nbsp; taskXmlNode.AppendChild(child);<br \/>&nbsp;&nbsp;&nbsp; parent = child;<br \/>&nbsp;&nbsp;&nbsp; child = doc.CreateNode(XmlNodeType.Element, &#8220;property&#8221;, String.Empty);<br \/>&nbsp;&nbsp;&nbsp; AddAttribute(doc, child, &#8220;name&#8221;, &#8220;MSPROJ&#8221;);<br \/>&nbsp;&nbsp;&nbsp; AddAttribute(doc, child, &#8220;value&#8221;, @&#8221;Classification\\FileMapping.xml&#8221;);<br \/>&nbsp;&nbsp;&nbsp; AddAttribute(doc, child, &#8220;isFile&#8221;, &#8220;true&#8221;);<br \/>&nbsp;&nbsp;&nbsp; parent.AppendChild(child);<br \/><\/font><\/p>\n<p>Brian<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/MSDNBlogsFS\/prod.evol.blogs.msdn.com\/CommunityServer.Components.PostAttachments\/00\/00\/72\/83\/33\/ExportClassifications.zip\">ExportClassifications.zip<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A couple of days ago someone asked me how to export the areas and iterations from one project and be able to use them as a template to create other projects.&nbsp; Creating a set of pre-defined Areas &amp; Iterations is a feature of the TFS process templates.&nbsp; In this post I&#8217;ve included a sample to [&hellip;]<\/p>\n","protected":false},"author":244,"featured_media":14617,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-10491","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"acf":[],"blog_post_summary":"<p>A couple of days ago someone asked me how to export the areas and iterations from one project and be able to use them as a template to create other projects.&nbsp; Creating a set of pre-defined Areas &amp; Iterations is a feature of the TFS process templates.&nbsp; In this post I&#8217;ve included a sample to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/bharry\/wp-json\/wp\/v2\/posts\/10491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/bharry\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/bharry\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/bharry\/wp-json\/wp\/v2\/users\/244"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/bharry\/wp-json\/wp\/v2\/comments?post=10491"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/bharry\/wp-json\/wp\/v2\/posts\/10491\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/bharry\/wp-json\/wp\/v2\/media\/14617"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/bharry\/wp-json\/wp\/v2\/media?parent=10491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/bharry\/wp-json\/wp\/v2\/categories?post=10491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/bharry\/wp-json\/wp\/v2\/tags?post=10491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}