<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ankit Jain &#187; tfs</title>
	<atom:link href="http://ankitjain.info/ankit/tag/tfs/feed/" rel="self" type="application/rss+xml" />
	<link>http://ankitjain.info/ankit</link>
	<description>» It’s all about Ankit and Web! «</description>
	<lastBuildDate>Thu, 02 Jun 2011 16:54:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>TFS &#8211; Free Text search in History Objects</title>
		<link>http://ankitjain.info/ankit/2007/05/29/tfs-free-text-search-in-history-objects/</link>
		<comments>http://ankitjain.info/ankit/2007/05/29/tfs-free-text-search-in-history-objects/#comments</comments>
		<pubDate>Tue, 29 May 2007 07:52:33 +0000</pubDate>
		<dc:creator>Ankit</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Programming/Code]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[tfs]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://ankitjain.info/ankit/2007/05/29/tfs-%e2%80%93-free-text-search-in-history-objects</guid>
		<description><![CDATA[It&#8217;s a best practice to add comment when you do check-in to the source control. A text comment is associated with the change you made to the item. Some of the times you need to find a particular comment, but the View History tool available with Visual Studio/TFS is limited that you can&#8217;t make a [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a best practice to add comment when you do check-in to the source control. A text comment is associated with the change you made to the item. Some of the times you need to find a particular comment, but the <em>View History</em> tool available with Visual Studio/TFS is limited that you can&#8217;t make a search in the history results. Say you want to find all check-ins by a particular user <img src='http://ankitjain.info/ankit/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p><img alt="History Tool in Visual Studio 2005" src="http://ankitjain.info/ankit/wp-content/052907_0752_TFSFreeText12.png" /></p>
<p>Here comes the purpose of this small add-in. It provides search within history comments and find a particular change-set instead of traversing the whole list. The plug-in goes one step forward and facilitates free text search in change-set fields. For example you can use change-set id, username or even date-time as search keywords!!!</p>
<p>The major steps involved in developing this add-in are:</p>
<ol>
<li>Writing an add-in for Visual Studio 2005,</li>
<li>Getting file history from Team Foundation Server (TFS),</li>
<li>Look for the selected item in the Visual Studio IDE,</li>
<li>Free text search along with the tools to compare two files.</li>
</ol>
<p><span id="more-97"></span></p>
<p>Visual Studio 2005 provides templates to build add-ins in few minutes. Refer <a target="_blank" href="http://www.devx.com/vstudioextensibility/Article/31354">www.devx.com</a> for step-by-step guide for building Visual Studio app-ins. Additionally, you can download <a target="_blank" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=79c7e038-8768-4e1e-87ae-5bbbe3886de8&#038;displaylang=en">Visual Studio 2005 Automation Samples</a> for detailed code illustrations with documentation.</p>
<p>Once you have completed the <em>Visual Studio Add-in wizard</em> the IDE generates <span style="font-family: Courier New; font-size: 10pt">Connect.cs</span> file and dumps some code for basic functionality. The next step is to retrieve history from the TFS for selected file. Refer my previous post, <a href="http://ankitjain.info/ankit/2006/12/13/tfs-version-control-build-history">Fetching file history from TFS</a> to find out how to fetch file history objects from Version Control Server.</p>
<p>Moving forward we need to find out the currently selected item in the Visual Studio IDE. Visual Studio exposes various properties/objects allowing you to query almost any UI controls and get their status.  The following code first finds the active window. If it is Source Control Explorer and then looks for the selected item within the same.</p>
<p><!--<br />
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;\red0\green128\blue0;\red163\green21\blue21;}??\fs20 \cf1 public\cf0  \cf1 static\cf0  \cf1 void\cf0  GetServerUriAndItemPath(\cf4 DTE2\cf0  appObj, \cf1 ref\cf0  \cf1 string\cf0  serverUri, \cf1 ref\cf0  \cf1 string\cf0  itemPath, \cf1 ref\cf0  \cf1 bool\cf0  isFolder)\par ??\{\par ??    isFolder = \cf1 false\cf0 ;\par ??\par ??    \cf5 // Get local workspace info\par ??\cf0     \cf4 WorkspaceInfo\cf0 [] wsInfo = \cf4 Workstation\cf0 .Current.GetAllLocalWorkspaceInfo();\par ??    \cf1 if\cf0  (wsInfo.Length == 0)\par ??        \cf1 throw\cf0  \cf1 new\cf0  \cf4 TFSHistorySearchException\cf0 (\cf6 "No workspace found."\cf0 );\par ??\par ??    \cf5 // Get server Uri\par ??\cf0     serverUri = wsInfo[0].ServerUri.AbsoluteUri;\par ??\par ??    \cf5 //\'a0Get\'a0a\'a0reference\'a0to the\'a0Team\'a0Foundation\'a0Server. \par ??\cf0     \cf4 TeamFoundationServer\cf0  tfs = \cf1 new\cf0  \cf4 TeamFoundationServer\cf0 (serverUri);\par ??    \cf4 VersionControlServer\cf0  vcs = tfs.GetService(\cf1 typeof\cf0 (\cf4 VersionControlServer\cf0 )) \cf1 as\cf0  \cf4 VersionControlServer\cf0 ;\par ??\par ??    \cf5 //if Active Window is Source Control Explorer\par ??\cf0     \cf1 if\cf0  (appObj.ActiveWindow.Caption.StartsWith(\cf6 "Source Control Explorer"\cf0 ))\par ??    \{\par ??        \cf4 VersionControlExt\cf0  vce;\par ??        \cf5 // The top level class used to access all other Team Foundation Version Control Extensiblity classes\par ??\cf0         vce = appObj.GetObject(\cf6 "Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt"\cf0 ) \cf1 as\cf0  \cf4 VersionControlExt\cf0 ;\par ??\par ??        \cf1 if\cf0  (!vce.Explorer.Connected)\par ??        \{\par ??            \cf1 throw\cf0  \cf1 new\cf0  \cf4 TFSHistorySearchException\cf0 (\cf6 "Source control explorer is not connected to a Team Foundation Server"\cf0 );\par ??        \}\par ??\par ??        \cf5 // Get all selected items\par ??\cf0         \cf4 VersionControlExplorerItem\cf0  []selectedItems = vce.Explorer.SelectedItems;\par ??\par ??        \cf1 if\cf0  (selectedItems.Length == 0)\par ??            \cf1 throw\cf0  \cf1 new\cf0  \cf4 TFSHistorySearchException\cf0 (\cf6 "You must select one item."\cf0 );\par ??\par ??        \cf1 if\cf0  (selectedItems.Length &amp;amp;gt; 1)\par ??            \cf1 throw\cf0  \cf1 new\cf0  \cf4 TFSHistorySearchException\cf0 (\cf6 "Multiple items selected."\cf0 );\par ??\par ??        \cf1 if\cf0  (selectedItems[0].SourceServerPath.Equals(\cf6 "$/"\cf0 ))\par ??            \cf1 throw\cf0  \cf1 new\cf0  \cf4 TFSHistorySearchException\cf0 (\cf6 "Operation is not supported for the selected item."\cf0 );\par ??        \cf5 //Take the 1st item\par ??\cf0         itemPath = selectedItems[0].SourceServerPath;\par ??        isFolder = selectedItems[0].IsFolder;\par ??    \}\par ??    \cf5 //if Active Window is Solution Explorer\par ??\cf0     \cf1 else\cf0  \cf1 if\cf0  (appObj.ActiveWindow.Caption.StartsWith(\cf6 "Solution Explorer"\cf0 ))\par ??    \{\par ??        isFolder = \cf1 false\cf0 ;\par ??        \cf1 if\cf0  (appObj.SelectedItems.MultiSelect == \cf1 true\cf0 )\par ??            \cf1 throw\cf0  \cf1 new\cf0  \cf4 TFSHistorySearchException\cf0 (\cf6 "Multiple items selected."\cf0 );\par ??\par ??        \cf4 SelectedItem\cf0  selectedItem = appObj.SelectedItems.Item(1);\par ??\par ??        \cf4 SourceControl2\cf0  sc = (\cf4 SourceControl2\cf0 )appObj.SourceControl;\par ??\par ??        \cf1 string\cf0  fileName = \cf4 String\cf0 .Empty;\par ??        \cf1 if\cf0  (selectedItem.ProjectItem != \cf1 null\cf0 )\par ??        \{\par ??            \cf5 //Its a project file\par ??\cf0             fileName = selectedItem.ProjectItem.Properties.Item(\cf6 "URL"\cf0 ).Value.ToString();\par ??            fileName = \cf4 Regex\cf0 .Replace(fileName, \cf6 "file:///"\cf0 , \cf4 String\cf0 .Empty, \cf4 RegexOptions\cf0 .IgnoreCase);\par ??            \cf1 if\cf0  (fileName.EndsWith(\cf6 "\\\\"\cf0 ))\par ??            \{\par ??                fileName = fileName.Substring(0, fileName.LastIndexOf(\cf6 '\\\\'\cf0 ));\par ??                isFolder = \cf1 true\cf0 ;\par ??            \}\par ??            \cf1 try\par ??\cf0             \{\par ??                \cf4 Item\cf0  item = vcs.GetItem(fileName);\par ??                itemPath = item.ServerItem;\par ??            \}\par ??            \cf1 catch\cf0  (Microsoft.TeamFoundation.VersionControl.Client.\cf4 VersionControlException\cf0  ex)\par ??            \{\par ??                \cf1 throw\cf0  \cf1 new\cf0  \cf4 TFSHistorySearchException\cf0 (\cf6 "Item not under source control."\cf0 , ex);\par ??            \}\par ??        \}\par ??        \cf1 else\cf0  \cf1 if\cf0  (selectedItem.Project != \cf1 null\cf0 )\par ??        \{\par ??            \cf5 //Its a project\par ??\cf0             fileName = selectedItem.Project.FileName;\par ??            \cf1 try\par ??\cf0             \{\par ??                \cf4 Item\cf0  item = vcs.GetItem(fileName);\par ??                itemPath = item.ServerItem;\par ??            \}\par ??            \cf1 catch\cf0  (Microsoft.TeamFoundation.VersionControl.Client.\cf4 VersionControlException\cf0  ex)\par ??            \{\par ??                \cf1 throw\cf0  \cf1 new\cf0  \cf4 TFSHistorySearchException\cf0 (\cf6 "Item not under source control."\cf0 , ex);\par ??            \}\par ??        \}\par ??        \cf1 else\par ??\cf0         \{\par ??            \cf1 throw\cf0  \cf1 new\cf0  \cf4 TFSHistorySearchException\cf0 (\cf6 "Operation is not supported for the selected item."\cf0 );\par ??        \}\par ??    \}\par ??    \cf1 else\par ??\cf0     \{\par ??        \cf1 throw\cf0  \cf1 new\cf0  \cf4 TFSHistorySearchException\cf0 (\cf6 "Operation is not supported for the selected item."\cf0 );\par ??    \}\par ??\}\par ??}<br />
--></p>
<div style="background: white none repeat scroll 0% 50%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">
<p style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: blue">void</span> GetServerUriAndItemPath(<span style="color: #2b91af">DTE2</span> appObj, <span style="color: blue">ref</span> <span style="color: blue">string</span> serverUri, <span style="color: blue">ref</span> <span style="color: blue">string</span> itemPath, <span style="color: blue">ref</span> <span style="color: blue">bool</span> isFolder)</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">isFolder = <span style="color: blue">false</span>;</p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: green">// Get local workspace info</span></p>
<p style="margin: 0px"><span style="color: #2b91af">WorkspaceInfo</span>[] wsInfo = <span style="color: #2b91af">Workstation</span>.Current.GetAllLocalWorkspaceInfo();</p>
<p style="margin: 0px"><span style="color: blue">if</span> (wsInfo.Length == 0)</p>
<p style="margin: 0px"><span style="color: blue">throw</span> <span style="color: blue">new</span> <span style="color: #2b91af">TFSHistorySearchException</span>(<span style="color: #a31515">&#8220;No workspace found.&#8221;</span>);</p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: green">// Get server Uri</span></p>
<p style="margin: 0px">serverUri = wsInfo[0].ServerUri.AbsoluteUri;</p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: green">// Get a reference to the Team Foundation Server. </span></p>
<p style="margin: 0px"><span style="color: #2b91af">TeamFoundationServer</span> tfs = <span style="color: blue">new</span> <span style="color: #2b91af">TeamFoundationServer</span>(serverUri);</p>
<p style="margin: 0px"><span style="color: #2b91af">VersionControlServer</span> vcs = tfs.GetService(<span style="color: blue">typeof</span>(<span style="color: #2b91af">VersionControlServer</span>)) <span style="color: blue">as</span> <span style="color: #2b91af">VersionControlServer</span>;</p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: green">//if Active Window is Source Control Explorer</span></p>
<p style="margin: 0px"><span style="color: blue">if</span> (appObj.ActiveWindow.Caption.StartsWith(<span style="color: #a31515">&#8220;Source Control Explorer&#8221;</span>))</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"><span style="color: #2b91af">VersionControlExt</span> vce;</p>
<p style="margin: 0px"><span style="color: green">// The top level class used to access all other Team Foundation Version Control Extensiblity classes</span></p>
<p style="margin: 0px">vce = appObj.GetObject(<span style="color: #a31515">&#8220;Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt&#8221;</span>) <span style="color: blue">as</span> <span style="color: #2b91af">VersionControlExt</span>;</p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: blue">if</span> (!vce.Explorer.Connected)</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"><span style="color: blue">throw</span> <span style="color: blue">new</span> <span style="color: #2b91af">TFSHistorySearchException</span>(<span style="color: #a31515">&#8220;Source control explorer is not connected to a Team Foundation Server&#8221;</span>);</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: green">// Get all selected items</span></p>
<p style="margin: 0px"><span style="color: #2b91af">VersionControlExplorerItem</span> []selectedItems = vce.Explorer.SelectedItems;</p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: blue">if</span> (selectedItems.Length == 0)</p>
<p style="margin: 0px"><span style="color: blue">throw</span> <span style="color: blue">new</span> <span style="color: #2b91af">TFSHistorySearchException</span>(<span style="color: #a31515">&#8220;You must select one item.&#8221;</span>);</p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: blue">if</span> (selectedItems.Length &gt; 1)</p>
<p style="margin: 0px"><span style="color: blue">throw</span> <span style="color: blue">new</span> <span style="color: #2b91af">TFSHistorySearchException</span>(<span style="color: #a31515">&#8220;Multiple items selected.&#8221;</span>);</p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: blue">if</span> (selectedItems[0].SourceServerPath.Equals(<span style="color: #a31515">&#8220;$/&#8221;</span>))</p>
<p style="margin: 0px"><span style="color: blue">throw</span> <span style="color: blue">new</span> <span style="color: #2b91af">TFSHistorySearchException</span>(<span style="color: #a31515">&#8220;Operation is not supported for the selected item.&#8221;</span>);</p>
<p style="margin: 0px"><span style="color: green">//Take the 1st item</span></p>
<p style="margin: 0px">itemPath = selectedItems[0].SourceServerPath;</p>
<p style="margin: 0px">isFolder = selectedItems[0].IsFolder;</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px"><span style="color: green">//if Active Window is Solution Explorer</span></p>
<p style="margin: 0px"><span style="color: blue">else</span> <span style="color: blue">if</span> (appObj.ActiveWindow.Caption.StartsWith(<span style="color: #a31515">&#8220;Solution Explorer&#8221;</span>))</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">isFolder = <span style="color: blue">false</span>;</p>
<p style="margin: 0px"><span style="color: blue">if</span> (appObj.SelectedItems.MultiSelect == <span style="color: blue">true</span>)</p>
<p style="margin: 0px"><span style="color: blue">throw</span> <span style="color: blue">new</span> <span style="color: #2b91af">TFSHistorySearchException</span>(<span style="color: #a31515">&#8220;Multiple items selected.&#8221;</span>);</p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: #2b91af">SelectedItem</span> selectedItem = appObj.SelectedItems.Item(1);</p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: #2b91af">SourceControl2</span> sc = (<span style="color: #2b91af">SourceControl2</span>)appObj.SourceControl;</p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: blue">string</span> fileName = <span style="color: #2b91af">String</span>.Empty;</p>
<p style="margin: 0px"><span style="color: blue">if</span> (selectedItem.ProjectItem != <span style="color: blue">null</span>)</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"><span style="color: green">//Its a project file</span></p>
<p style="margin: 0px">fileName = selectedItem.ProjectItem.Properties.Item(<span style="color: #a31515">&#8220;URL&#8221;</span>).Value.ToString();</p>
<p style="margin: 0px">fileName = <span style="color: #2b91af">Regex</span>.Replace(fileName, <span style="color: #a31515">&#8220;file:///&#8221;</span>, <span style="color: #2b91af">String</span>.Empty, <span style="color: #2b91af">RegexOptions</span>.IgnoreCase);</p>
<p style="margin: 0px"><span style="color: blue">if</span> (fileName.EndsWith(<span style="color: #a31515">&#8220;\\&#8221;</span>))</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">fileName = fileName.Substring(0, fileName.LastIndexOf(<span style="color: #a31515">&#8216;\\&#8217;</span>));</p>
<p style="margin: 0px">isFolder = <span style="color: blue">true</span>;</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px"><span style="color: blue">try</span></p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"><span style="color: #2b91af">Item</span> item = vcs.GetItem(fileName);</p>
<p style="margin: 0px">itemPath = item.ServerItem;</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px"><span style="color: blue">catch</span> (Microsoft.TeamFoundation.VersionControl.Client.<span style="color: #2b91af">VersionControlException</span> ex)</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"><span style="color: blue">throw</span> <span style="color: blue">new</span> <span style="color: #2b91af">TFSHistorySearchException</span>(<span style="color: #a31515">&#8220;Item not under source control.&#8221;</span>, ex);</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px"><span style="color: blue">else</span> <span style="color: blue">if</span> (selectedItem.Project != <span style="color: blue">null</span>)</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"><span style="color: green">//Its a project</span></p>
<p style="margin: 0px">fileName = selectedItem.Project.FileName;</p>
<p style="margin: 0px"><span style="color: blue">try</span></p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"><span style="color: #2b91af">Item</span> item = vcs.GetItem(fileName);</p>
<p style="margin: 0px">itemPath = item.ServerItem;</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px"><span style="color: blue">catch</span> (Microsoft.TeamFoundation.VersionControl.Client.<span style="color: #2b91af">VersionControlException</span> ex)</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"><span style="color: blue">throw</span> <span style="color: blue">new</span> <span style="color: #2b91af">TFSHistorySearchException</span>(<span style="color: #a31515">&#8220;Item not under source control.&#8221;</span>, ex);</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px"><span style="color: blue">else</span></p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"><span style="color: blue">throw</span> <span style="color: blue">new</span> <span style="color: #2b91af">TFSHistorySearchException</span>(<span style="color: #a31515">&#8220;Operation is not supported for the selected item.&#8221;</span>);</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px"><span style="color: blue">else</span></p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"><span style="color: blue">throw</span> <span style="color: blue">new</span> <span style="color: #2b91af">TFSHistorySearchException</span>(<span style="color: #a31515">&#8220;Operation is not supported for the selected item.&#8221;</span>);</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px">}</p>
</div>
<p>The following code is to compare two source code files and show visual difference. There is an API provided for the same.</p>
<p><!--<br />
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;}??\fs20 \cf1 public\cf0  \cf1 static\cf0  \cf1 void\cf0  CompareLocal(\cf1 string\cf0  localPath, \cf1 string\cf0  sourceChangesetId, \cf1 string\cf0  serverUri, \cf1 string\cf0  srcPath)\par ??\{\par ??    \cf4 TeamFoundationServer\cf0  tfs = \cf4 TeamFoundationServerFactory\cf0 .GetServer(serverUri);\par ??    \cf4 VersionControlServer\cf0  vcs = tfs.GetService(\cf1 typeof\cf0 (\cf4 VersionControlServer\cf0 )) \cf1 as\cf0  \cf4 VersionControlServer\cf0 ;\par ??\par ??    \cf4 VersionSpec\cf0  sourceVersion = \cf4 VersionSpec\cf0 .ParseSingleSpec(sourceChangesetId, vcs.TeamFoundationServer.AuthenticatedUserName);\par ??\par ??    \cf4 Difference\cf0 .VisualDiffItems(vcs, \cf4 Difference\cf0 .CreateTargetDiffItem(vcs, srcPath, sourceVersion, 0, sourceVersion), \cf4 Difference\cf0 .CreateTargetDiffItem(vcs, localPath, \cf1 null\cf0 , 0, \cf1 null\cf0 ));\par ??\}\par ??}<br />
--></p>
<div style="background: white none repeat scroll 0% 50%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">
<p style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: blue">void</span> CompareLocal(<span style="color: blue">string</span> localPath, <span style="color: blue">string</span> sourceChangesetId, <span style="color: blue">string</span> serverUri, <span style="color: blue">string</span> srcPath)</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"><span style="color: #2b91af">TeamFoundationServer</span> tfs = <span style="color: #2b91af">TeamFoundationServerFactory</span>.GetServer(serverUri);</p>
<p style="margin: 0px"><span style="color: #2b91af">VersionControlServer</span> vcs = tfs.GetService(<span style="color: blue">typeof</span>(<span style="color: #2b91af">VersionControlServer</span>)) <span style="color: blue">as</span> <span style="color: #2b91af">VersionControlServer</span>;</p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: #2b91af">VersionSpec</span> sourceVersion = <span style="color: #2b91af">VersionSpec</span>.ParseSingleSpec(sourceChangesetId, vcs.TeamFoundationServer.AuthenticatedUserName);</p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: #2b91af">Difference</span>.VisualDiffItems(vcs, <span style="color: #2b91af">Difference</span>.CreateTargetDiffItem(vcs, srcPath, sourceVersion, 0, sourceVersion), <span style="color: #2b91af">Difference</span>.CreateTargetDiffItem(vcs, localPath, <span style="color: blue">null</span>, 0, <span style="color: blue">null</span>));</p>
<p style="margin: 0px">}</p>
</div>
<p>Once the add-in is installed, it appears in the Tools menu within Visual Studio 2005. Open <em>Source Control Explorer</em> and select an item. Launch the add-in from Tools menu.</p>
<p><img src="http://ankitjain.info/ankit/wp-content/052907_0752_TFSFreeText22.png" /></p>
<p>When you search for the history of a File, you can also compare it with the local version or the latest version in the source control. These option are avaiable as context menu.</p>
<p><img src="http://ankitjain.info/ankit/wp-content/052907_0752_TFSFreeText32.png" /></p>
<p><img alt="Compare options for search results (only for file types)" src="http://ankitjain.info/ankit/wp-content/TFS-History-Compare.PNG" /></p>
<p>Following steps are required only if you download the code and try to deploy the solution to have hands on with the code.</p>
<ol>
<li>Copy the <span style="font-family: Courier New; font-size: 10pt">TFSHistorySearch.AddIn</span> file to <span style="font-family: Courier New; font-size: 10pt">%userprofile%\My Documents\Visual Studio 2005\Addins\</span> directory.</li>
<li>Update the full path of the assembly <span style="font-family: Courier New; font-size: 10pt">TFSHistorySearch.dll </span>under <span style="font-family: Courier New; font-size: 10pt">Extensibility/Addin/Assembly</span> x-path.</li>
<li>Add reference of <span style="font-family: Courier New; font-size: 10pt">TFSHistorySearch.AddIn</span> as link to the project.</li>
</ol>
<p>Download Source code &#038; Installer: <a href="http://ankitjain.info/ankit/wp-content/TFSHistorySearch.zip">TFSHistorySearch.zip</a> ~700 KB<br />
Download Installer only: <a href="http://ankitjain.info/ankit/wp-content/TFSHistorySearch-Setup.zip">TFSHistorySearch-Setup.zip</a> ~400 KB</p>
<p>Implemented by:  <a target="_blank" href="http://www.topcoder.com/tc?module=MemberProfile&#038;cr=15892009&#038;tab=long">Jagdish.Vasani</a> [at] Gmail [dot] com</p>
<p>- Ankit</p>
]]></content:encoded>
			<wfw:commentRss>http://ankitjain.info/ankit/2007/05/29/tfs-free-text-search-in-history-objects/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

