Monday, March 5, 2012

Enabling logging on MSTest.exe

Many times you might need to enable verbose logging on MSTest.exe to debug the Test related issue on the build machine.

Here are the steps

Step 1: Find the MSTest.exe.config file on the build machine. It can be found at the following location
<Drive:>\Program Files\Microsoft Visual Studio 10.0\Common7\IDE

Step 2: Make a backup copy of MSTest.exe.config file

Step 3: Add the following <system.diagnostics> in the MSTest.exe.config file
<system.diagnostics>
    <trace autoflush="true" indentsize="4">
      <listeners>
        <add name="EqtListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\Temp\MSTestTrace.log" />
      </listeners>
    </trace>
    <switches>
      <add name="EqtTraceLevel" value="Verbose" />
    </switches>
  </system.diagnostics>

Step 4: Here is the sample updated file.

<?xml version ="1.0"?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="PrivateAssemblies;PublicAssemblies;PrivateAssemblies\DataCollectors;PrivateAssemblies\DataCollectors\x86"/>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.UnitTestFramework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="10.1.0.0" newVersion="10.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="10.1.0.0" newVersion="10.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="10.1.0.0" newVersion="10.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Tip" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="10.1.0.0" newVersion="10.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
<system.diagnostics>
    <trace autoflush="true" indentsize="4">
      <listeners>
        <add name="EqtListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\Temp\MSTestTrace.log" />
      </listeners>
    </trace>
    <switches>
      <add name="EqtTraceLevel" value="Verbose" />
    </switches>
  </system.diagnostics>
  <appSettings>
    <add key="GetCollectorDataTimeout" value="300"/>
    <add key="TestProjectRetargetTo35Allowed" value="true" />
  </appSettings>
</configuration>

Step 5: Restart the “Visual Studio Team Foundation Build Service Host” service on build machine. The next build would log the detail.

Friday, March 2, 2012

Disable All Build Definitions, Build Controllers and Build Agents using SQL

We had a situation where we need to disable all the build definitions, build controllers and build agents without bringing TFS up and running. This was on QA instance, we backed up and restored the database on QA from Prod, so when we brought QA TFS up, TFS QA started running all the scheduled builds on Prod build controllers, which caused the problem.

Here are the SQL commands I ran on TFS QA database, which disabled all the 600+ build definitions and 100+ controllers

Use TFS_<Collection Name>

--Disable Build Agents

Update dbo.tbl_BuildAgent Set [Enabled]= 0 Where [Enabled]=1

--Disable Controllers

Update dbo.tbl_BuildController Set [Enabled]= 0 Where [Enabled] =1

--Disable Build definitions

Update dbo.tbl_BuildDefinition Set [Enabled]= 0 Where [Enabled] =1