<?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>dotnet thoughts &#187; .Net</title>
	<atom:link href="http://www.dotnetthoughts.net/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>a dotnet developer&#039;s technical blog</description>
	<lastBuildDate>Thu, 02 Feb 2012 03:18:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail</title>
		<link>http://www.dotnetthoughts.net/2012/02/01/the-application-has-failed-to-start-because-its-side-by-side-configuration-is-incorrect-please-see-the-application-event-log-or-use-the-command-line-sxstrace-exe-tool-for-more-detail/</link>
		<comments>http://www.dotnetthoughts.net/2012/02/01/the-application-has-failed-to-start-because-its-side-by-side-configuration-is-incorrect-please-see-the-application-event-log-or-use-the-command-line-sxstrace-exe-tool-for-more-detail/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 03:18:00 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[sxstrace]]></category>
		<category><![CDATA[sxstrace.exe]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=2332</guid>
		<description><![CDATA[Today I got a comment from Vitor, Vitor is getting an exception like this while starting application. The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe &#8230; <a href="http://www.dotnetthoughts.net/2012/02/01/the-application-has-failed-to-start-because-its-side-by-side-configuration-is-incorrect-please-see-the-application-event-log-or-use-the-command-line-sxstrace-exe-tool-for-more-detail/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today I got a <a href="http://www.dotnetthoughts.net/2010/12/22/net-framework-initialization-error-%E2%80%93-unable-to-find-a-version-of-the-runtime-to-run-this-application/#comment-699">comment from Vitor</a>, Vitor is getting an exception like this while starting application.</p>
<blockquote><p>The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.</p></blockquote>
<p>So I thought of work around this issue. To reproduce the issue, I tampered the exe.config file of one of my application, by removing &lt;configuration&gt; tag from the file. And it started throwing the exception.</p>
<div id="attachment_2336" class="wp-caption aligncenter" style="width: 310px"><img src="http://www.dotnetthoughts.net/wp-content/uploads/2012/02/side_by_side-300x96.jpg" alt="The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail." title="The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail." width="300" height="96" class="size-medium wp-image-2336" /><p class="wp-caption-text">The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.</p></div>
<p>I verified the same with EventViewer, and I found a message like this, under Windows Logs > Application </p>
<blockquote><p>Activation context generation failed for &#8220;C:\CaptureItPlus\Binaries\CaptureItPlus.exe&#8221;. Error in manifest or policy file &#8220;C:\CaptureItPlus\Binaries\CaptureItPlus.exe.Config&#8221; on line 1. Invalid Xml syntax. </p></blockquote>
<p>The error message is pretty self explanatory. If you are not able to access the event viewer, the other option is using sxstrace.exe tool. You can enable run the sxstrace in trace mode, you can do this by following command.</p>
<pre class="brush: plain; title: ; notranslate">
sxstrace.exe Trace -logfile:C:\captureittrace.log
</pre>
<p>And execute the application. After getting exception, stop the tracing and you can parse the log file using following command.</p>
<pre class="brush: plain; title: ; notranslate">
sxstrace.exe Parse -logfile:C:\captureittrace.log -outfile:C:\captureittrace.txt
</pre>
<p>It is required because .log is a binary file. Now open the .txt file, you can see similar message,</p>
<blockquote><p>INFO: Parsing Application Config File C:\CaptureItPlus\Binaries\CaptureItPlus.exe.Config.<br />
ERROR: Line 1: XML Syntax error.<br />
ERROR: Activation Context generation failed.<br />
End Activation Context Generation.</p></blockquote>
<p>Now open the .exe.config and add the missing <configuration>, now double click on the application, this issue will be resolved. <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </configuration></p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2012/01/11/how-to-use-net-assembly-in-vbscript/" title="Permanent link to How to use .Net assembly in VBScript">How to use .Net assembly in VBScript</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/11/02/debugging-nunit-tests-in-visual-studio-2010/" title="Permanent link to Debugging NUnit Tests in Visual Studio 2010">Debugging NUnit Tests in Visual Studio 2010</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/06/30/how-to-use-taskdialog-api-in-c/" title="Permanent link to How to use TaskDialog API in C#">How to use TaskDialog API in C#</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/08/03/windows-7-sdk-installation-success-or-error-status-1603/" title="Permanent link to Windows 7 SDK Installation success or error status: 1603">Windows 7 SDK Installation success or error status: 1603</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/01/18/how-to-unit-test-asynchronous-callbacks/" title="Permanent link to How to unit test asynchronous callbacks">How to unit test asynchronous callbacks</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2012/02/01/the-application-has-failed-to-start-because-its-side-by-side-configuration-is-incorrect-please-see-the-application-event-log-or-use-the-command-line-sxstrace-exe-tool-for-more-detail/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to write an NUnit Addin</title>
		<link>http://www.dotnetthoughts.net/2012/01/23/how-to-write-an-nunit-addin/</link>
		<comments>http://www.dotnetthoughts.net/2012/01/23/how-to-write-an-nunit-addin/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 04:51:09 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[NUnit]]></category>
		<category><![CDATA[NUnit AddIn]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=2309</guid>
		<description><![CDATA[From version 2.2.x NUnit supports AddIns. Addins can customize NUnit’s internal behavior such as the creation of tests and their execution. An Addin should to implement the interface NUnit.Core.Extensibility.IAddin, which can be found in the assembly nunit.core.interfaces. Also the NUnit.Core.Extensibility.NUnitAddinAttribute &#8230; <a href="http://www.dotnetthoughts.net/2012/01/23/how-to-write-an-nunit-addin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">From version 2.2.x NUnit supports AddIns. Addins can customize NUnit’s internal behavior such as the creation of tests and their execution. An Addin should to implement the interface <em>NUnit.Core.Extensibility.IAddin</em>, which can be found in the assembly <em>nunit.core.interfaces</em>. Also the <em>NUnit.Core.Extensibility.NUnitAddinAttribute</em> must be applied to Addin class. The attribute parameters Name and Description represent the name of the extension and a description of what it does. The NUnit.Core.Extensibility.IAddin has only one method, Install(). The Install method is called by each host for which the addin has specified an ExtensionType. The addin should check that the necessary extension points are available and install itself, returning true for success or false for failure to install. The method will be called once for each extension host and &#8211; for Core extensions &#8211; each time a new test domain is loaded. Here is a minimal addin.</p>
<pre class="brush: csharp; title: ; notranslate">
namespace SampleAddIn
{
    using NUnit.Core.Extensibility;

    [NUnitAddin(Name = &quot;SampleAddIn&quot;, Description = &quot;This is a Sample AddIn&quot;)]
    public class SampleNUnitAddin : IAddin
    {
        #region IAddin Members

        public bool Install(IExtensionHost host)
        {
            return true;
        }

        #endregion
    }
}
</pre>
<p>You can install the Addin, by copying the assembly to bin\Addins folder, relative to NUnit installation directory. You can verify your addin by starting NUnit, Tools &gt; Addins menu.</p>
<div id="attachment_2311" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-2311" title="Registered AddIns Dialog" src="http://www.dotnetthoughts.net/wp-content/uploads/2012/01/nunit_addin-300x258.jpg" alt="Registered AddIns Dialog" width="300" height="258" /><p class="wp-caption-text">Registered AddIns Dialog</p></div>
<p>This Addin does nothing. It simply registers itself to NUnit. You can more details about NUnit Addins <a href="http://nunit.org/index.php?p=nunitAddins&amp;r=2.6">here</a><br />
If you are using VS2010, then please make sure your target framework is .Net 2.0. Otherwise Addin won&#8217;t work.</p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2011/01/05/how-to-compare-equality-between-two-objects-in-nunit/" title="Permanent link to How to compare equality between two objects in NUnit">How to compare equality between two objects in NUnit</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/11/02/debugging-nunit-tests-in-visual-studio-2010/" title="Permanent link to Debugging NUnit Tests in Visual Studio 2010">Debugging NUnit Tests in Visual Studio 2010</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/12/23/how-to-do-code-coverage-with-nunit-tests/" title="Permanent link to How to do code coverage with NUnit tests">How to do code coverage with NUnit tests</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/12/15/how-to-integrate-nunit-with-visual-studio-2008/" title="Permanent link to How to integrate Nunit with Visual Studio 2008">How to integrate Nunit with Visual Studio 2008</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/09/25/getting-code-coverage-using-open-cover-and-nunit/" title="Permanent link to Getting Code coverage using Open Cover and NUnit">Getting Code coverage using Open Cover and NUnit</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2012/01/23/how-to-write-an-nunit-addin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to add MEX endpoints programmatically</title>
		<link>http://www.dotnetthoughts.net/2012/01/22/how-to-add-mex-endpoints-programmatically/</link>
		<comments>http://www.dotnetthoughts.net/2012/01/22/how-to-add-mex-endpoints-programmatically/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 02:49:13 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Mex]]></category>
		<category><![CDATA[Mex EndPoint]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=2303</guid>
		<description><![CDATA[The Metadata Exchange Endpoint (MEX) is a special endpoint in WCF that exposes metadata used to describe a service.Without the MEX, you will not be able to use svcutil.exe to automatically generate a proxy class. Fortunately, it is a simply &#8230; <a href="http://www.dotnetthoughts.net/2012/01/22/how-to-add-mex-endpoints-programmatically/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The Metadata Exchange Endpoint (MEX) is a special endpoint in WCF that exposes metadata used to describe a service.Without the MEX, you will not be able to use svcutil.exe to automatically generate a proxy class.  Fortunately, it is a simply process to enable the MEX for your service. Here is the code which will add Mex endpoint programmatically. </p>
<pre class="brush: csharp; title: ; notranslate">
var metadataBehavior = serviceHost.Description.Behaviors.Find&lt;ServiceMetadataBehavior&gt;()
    ?? new ServiceMetadataBehavior();
serviceHost.Description.Behaviors.Add(metadataBehavior);
serviceHost.AddServiceEndpoint(typeof(IMetadataExchange),
    MetadataExchangeBindings.CreateMexHttpBinding(),
    &quot;http://localhost:8080/IService/Mex&quot;);
</pre>
<p>It should be noted that you are not required to enable HttpGet.  SvcUtil will still be able to access the MEX without it.  However, it is useful if you want to view the WSDL from a browser by going to the address of the service.  You cannot do so without enabling the HttpGet.</p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2011/12/26/how-to-configure-a-wcf-service-to-use-port-sharing/" title="Permanent link to How to configure a WCF service to use Port Sharing">How to configure a WCF service to use Port Sharing</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/06/24/wcf-callbacks-%e2%80%93-a-quick-introduction/" title="Permanent link to WCF Callbacks – A quick introduction">WCF Callbacks – A quick introduction</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/03/20/how-to-create-restful-wcf-services/" title="Permanent link to How to create RESTful WCF services">How to create RESTful WCF services</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/04/01/how-to-post-data-to-restful-wcf-service/" title="Permanent link to How to post data to RESTful WCF service">How to post data to RESTful WCF service</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2012/01/22/how-to-add-mex-endpoints-programmatically/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to execute ms tests in parallel on multi-cpu / core machines</title>
		<link>http://www.dotnetthoughts.net/2012/01/18/how-to-execute-ms-tests-in-parallel-on-multi-cpu-core-machines/</link>
		<comments>http://www.dotnetthoughts.net/2012/01/18/how-to-execute-ms-tests-in-parallel-on-multi-cpu-core-machines/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 07:17:47 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[MS Test]]></category>
		<category><![CDATA[MS Test Parallel]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=2278</guid>
		<description><![CDATA[VS 2010 supports running MS Tests in parallel. Most of the machines available in the market are multi-cpu / core machines. This will help us to increase the number of tests executing in same time, which will reduce total test &#8230; <a href="http://www.dotnetthoughts.net/2012/01/18/how-to-execute-ms-tests-in-parallel-on-multi-cpu-core-machines/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">VS 2010 supports running MS Tests in parallel. Most of the machines available in the market are multi-cpu / core machines. This will help us to increase the number of tests executing in same time, which will reduce total test time. But while writing tests, developers should make sure the tests are thread safe, if it is not, it may result in incorrect results, deadlocks etc.</p>
<p style="text-align: justify;">You can enable parallel test execution by editing the testsettings file, instead of double click and open the test settings dialog, open the file using Open with option in the context menu, and select XML(Text) Editor option, which open the testsettings file in XML Editor. In the XML, find the Execution element. Add parallelTestCount attribute to the Execution element(By default it will not be there).</p>
<div id="attachment_2292" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-2292" title="Parallel Test count attribute in testsettings file" src="http://www.dotnetthoughts.net/wp-content/uploads/2012/01/parallelTestcount_attribute-300x53.jpg" alt="Parallel Test count attribute in testsettings file" width="300" height="53" /><p class="wp-caption-text">Parallel Test count attribute in testsettings file</p></div>
<p style="text-align: justify;">By default it will be 1(if the attribute is not exists), other options are 0 for Auto configure we will use as many tests as we can based on your CPU and core count, and n, the number n of tests to run in parallel. Save the changes. Restart visual studio. And you are done.(Note: You need to restart visual studio, otherwise changes will not reflect.)</p>
<p>Here is a sample unit test</p>
<pre class="brush: csharp; title: ; notranslate">
[TestMethod]
public void TestMethod3()
{
    Console.WriteLine(Thread.CurrentThread.Name);
    Thread.Sleep(2000);
}
</pre>
<p>Now I am running few test cases (11) with no parallelTestCount attribute and here is the Test Results window and summary</p>
<div id="attachment_2283" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-2283" title="Test Results View - No attribute specified" src="http://www.dotnetthoughts.net/wp-content/uploads/2012/01/with_no_attribute-300x147.jpg" alt="Test Results View - No attribute specified" width="300" height="147" /><p class="wp-caption-text">Test Results View - No attribute specified</p></div>
<div id="attachment_2284" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-2284" title="Test Results summary - No attribute specified" src="http://www.dotnetthoughts.net/wp-content/uploads/2012/01/with_no_attribute_summary-300x139.jpg" alt="Test Results summary - No attribute specified" width="300" height="139" /><p class="wp-caption-text">Test Results summary - No attribute specified</p></div>
<p>Now I added the parallelTestCount attribute, with value of 5 and here is the Test Results window and summary, you can notice the time difference between two executions.</p>
<div id="attachment_2281" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-2281" title="Test Results View - parallelTestCount Attribute specified" src="http://www.dotnetthoughts.net/wp-content/uploads/2012/01/with_attribute-300x174.jpg" alt="Test Results View - parallelTestCount Attribute specified" width="300" height="174" /><p class="wp-caption-text">Test Results View - parallelTestCount Attribute specified</p></div>
<div id="attachment_2282" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-2282" title="Test Results Summary - With parallelTestCount attribute specified" src="http://www.dotnetthoughts.net/wp-content/uploads/2012/01/with_attribute_summary-300x153.jpg" alt="Test Results Summary - With parallelTestCount attribute specified" width="300" height="153" /><p class="wp-caption-text">Test Results Summary - With parallelTestCount attribute specified</p></div>
<p style="text-align: justify;">Of course there are many other factors that affect this. There is the cost of starting and tearing down the run, so you will see a lesser effect if you have a few tests. It also depends on the number of CPU/cores you have and of course how fast your tests execute.</p>
<p>Happy unit testing <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2011/11/22/mstest-exe-does-not-deploy-all-items/" title="Permanent link to MSTest.exe does not deploy all items">MSTest.exe does not deploy all items</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/12/23/how-to-do-code-coverage-with-nunit-tests/" title="Permanent link to How to do code coverage with NUnit tests">How to do code coverage with NUnit tests</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/01/29/quick-introduction-to-ms-test/" title="Permanent link to Quick introduction to MS Test">Quick introduction to MS Test</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/10/29/test-impact-analysis-in-visual-studio-2010/" title="Permanent link to Test impact analysis in Visual Studio 2010">Test impact analysis in Visual Studio 2010</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/01/05/how-to-compare-equality-between-two-objects-in-nunit/" title="Permanent link to How to compare equality between two objects in NUnit">How to compare equality between two objects in NUnit</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2012/01/18/how-to-execute-ms-tests-in-parallel-on-multi-cpu-core-machines/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to queue a new build using TFS API</title>
		<link>http://www.dotnetthoughts.net/2012/01/12/how-to-queue-a-new-build-using-tfs-api/</link>
		<comments>http://www.dotnetthoughts.net/2012/01/12/how-to-queue-a-new-build-using-tfs-api/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 05:26:25 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[Version Control]]></category>
		<category><![CDATA[Queue Build]]></category>
		<category><![CDATA[Team Foundation Server]]></category>
		<category><![CDATA[TFS]]></category>
		<category><![CDATA[TFS API]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=2260</guid>
		<description><![CDATA[Another post on TFS API, my last post was related to how to get build Definitions and Build Details from TFS 2010, and this post is about how to queue a new build in TFS 2010 Server. As earlier you &#8230; <a href="http://www.dotnetthoughts.net/2012/01/12/how-to-queue-a-new-build-using-tfs-api/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Another post on TFS API, my <a href="http://www.dotnetthoughts.net/2012/01/05/how-to-get-build-definitions-and-build-details-from-tfs-2010/">last post</a> was related to how to get build Definitions and Build Details from TFS 2010, and this post is about how to queue a new build in TFS 2010 Server.</p>
<p>As earlier you need to add reference of following assemblies</p>
<ol>
<li>Microsoft.TeamFoundation.dll</li>
<li>Microsoft.TeamFoundation.Client.dll</li>
<li>Microsoft.TeamFoundation.Build.Client.dll</li>
</ol>
<p>which will be available under – C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\ location.</p>
<p>And here is the code snippet</p>
<pre class="brush: csharp; title: ; notranslate">
var tfsName = &quot;http://dotnetthoughts:8080/tfs/defaultcollection&quot;;
var tfs = new TeamFoundationServer(tfsName, new UICredentialsProvider());
tfs.EnsureAuthenticated();
if (tfs.HasAuthenticated)
{
	var buildServer = tfs.GetService(typeof(IBuildServer)) as IBuildServer;
	var buildDefinition = buildServer.GetBuildDefinition(&quot;&quot;, &quot;&quot;);
	buildServer.QueueBuild(buildDefinition);
}
catch (Exception exception)
{
    MessageBox.Show(exception.Message);
    throw;
}
</pre>
<p style="text-align: justify;">Here is how it works, we are connecting and getting the TFS Server, then getting the Build Server using GetService method. And to get the build definition instead of the earlier post(to get all the Build definitions, we are passing &#8220;*&#8221;), we need to specify the Team project and Build name(Build definitions are unique per team project in TFS). Then we can call QueueBuild() method on Build server object, with build definition as the parameter, which will queue the build definition default values.</p>
<p>Happy coding <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2012/01/05/how-to-get-build-definitions-and-build-details-from-tfs-2010/" title="Permanent link to How to get Build Definitions and Build Details from TFS 2010">How to get Build Definitions and Build Details from TFS 2010</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/01/04/tfs-build-notification-tool/" title="Permanent link to TFS Build Notification Tool">TFS Build Notification Tool</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/02/21/how-to-store-tfs-credentials/" title="Permanent link to How to store TFS credentials">How to store TFS credentials</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/11/25/raven-db-introduction/" title="Permanent link to Raven DB &#8211; Introduction">Raven DB &#8211; Introduction</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/05/30/how-to-do-rollback-of-a-changeset-in-tfs-2010/" title="Permanent link to How to do Rollback of a change set in TFS 2010">How to do Rollback of a change set in TFS 2010</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2012/01/12/how-to-queue-a-new-build-using-tfs-api/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

