JG Vimalan's Blog

It is all about coding!

Automated builds created in TFS 2008 did not work in TFS 2010

I faced an issue with the automated builds recently. I created automated builds in tfs 2008 and they worked good. When the project sources are migrated to tfs 2010, all my builds are not work properly in tfs 2010.  Eventhough they succeeded, they did not pick the latest sources rather, an old source is found to be copied to the deployment server. After analysis I found that, in tfs 2010, there is an additional folder created in the path and it is the ‘Agent Id’. So I have updated the source path with the agent id as shown below,

<MyApplicationFiles Include=”D:\Builds\$(BuildAgentID)\$(BuildDefinitionId)\Binaries\debug\_PublishedWebsites\MyProject\**\*.*”/>

 this fixed the issue.

December 24, 2010 Posted by | TFS | Leave a comment

Error loading the changeset comments policy.

I got this error message when I tried to check in my changes into the tfs. I am not violating the check in policy as, I have associated my check in files with a task. This issue happened for me in VS 2010.

 So, to fix this issue, you need to install the TFS 2010 power tools. Please download and install the TFS 2010 power tools from the following location http://visualstudiogallery.msdn.microsoft.com/en-us/c255a1e4-04ba-4f68-8f4e-cd473d6b971f After installing the software, restart the Visual Studio. Now, the check in will work.

December 10, 2010 Posted by | TFS, VS 2010 | 2 Comments

Enable code coverage in VS 2010

Developers add unit tests for every method they write and it ensures quality of the application. To know the lines of code they have covered via unit tests, the code coverage should be enabled. Code coverage tells the developers, the various scenarios (using unit tests) they have covered for testing the methods. To enable code coverage follow the steps below,

a. I assume that, your application has a unit test project and a test list with unit test methods added to it. So, as a first step, in visual studio 2010 ultimate, goto Tests->Edit Test Settings ->Local (local.testsettings) as shown in the image below,

b. Now, the Test Settings dialog will appear. Select ‘Data and Diagnostics’ tab. Select ‘Code Coverage’.  Click on the ‘Configure’ link as shown in the image below,

Now, you will get a dialog window where you can select the assemblies, projects that come under your unit test.

c. Run the unit tests now.Once the test results are displayed, to view the code coverage results, Goto Tests->Windows->Code Coverage Results.

d. The code coverage results will be displayed as shown below,

Normally, code coverage of 85% is considered to be good.

December 9, 2010 Posted by | TFS, VS 2010 | Leave a comment

Connect to tfs via API and get the build status of team projects

The following code snippet  explains the way to connect to tfs programmatically and get the build status of team projects.

This will be helpful when you create a custom application to display the build status of certain team projects in tfs.

 using Microsoft.TeamFoundation.Client;
 using Microsoft.TeamFoundation.Build.Client;
 …
 …

 private IQueuedBuildsView[] myTfsQueuedBuilds= null;
 private IQueuedBuildsView myTfsBuildQueue;
         /// <summary>
        ///  Create initial connection to the TFS 2008 Build Server.
        /// </summary>
        public void Connect()
        {
            TeamFoundationServer tfs = new TeamFoundationServer(TfsUrl);
            IBuildServer buildServer = (IBuildServer)
            tfs.GetService(typeof (IBuildServer));
            ArrayList queuedBuildsList = new ArrayList();

            //teamProject is the string array of team project name in tfs
            foreach (string project in teamProject)
            {
                myTfsBuildQueue = buildServer.CreateQueuedBuildsView (project);               
               
                myTfsBuildQueue.StatusChanged += new
                       StatusChangedEventHandler(myTfsBuildQueue_StatusChanged);

               //1000 ms and ‘myForm’ is the instance of the page
                myTfsBuildQueue.Connect(1000, myForm);

                queuedBuildsList.Add(myTfsBuildQueue);
            }
           
            myTfsQueuedBuilds= new IQueuedBuildsView[queuedBuildsList.Count];
            for(int i=0; i<queuedBuildsList.Count; i++)
            {
                queuedBuilds[i] = (IQueuedBuildsView)queuedBuildsList[i];
            }
        }

        private void buildQueue_StatusChanged(object sender, StatusChangedEventArgs e)
        {
            foreach(IQueuedBuildsView qbv in queuedBuilds)
            {
                if (e.Changed && qbv.QueuedBuilds.Length > 0)
                {
                    foreach (IQueuedBuild qb in qbv.QueuedBuilds)
                    {
                        //update status in UI
                    }
                }
            }           
        }

October 28, 2010 Posted by | TFS | Leave a comment

Get latest sources from tfs using .bat file

I used to get latest sources from tfs several times a day. Also, I depend on multiple projects in tfs.  So, I created a simple .bat file to get the latest sources from multiple projects in tfs by a single click. Here is the code,
ECHO STARTING. PLEASE WAIT….

CD C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC
CALL vcvarsall.bat x86
tf.exe GET ITEMSPEC /FORCE /ALL /OVERWRITE /RECURSIVE $/ProjectA
tf.exe GET ITEMSPEC /FORCE /ALL /OVERWRITE /RECURSIVE $/ProjectB
tf.exe GET ITEMSPEC /FORCE /ALL /OVERWRITE /RECURSIVE $/ProjectC/Binaries
tf.exe GET ITEMSPEC /FORCE /ALL /OVERWRITE /RECURSIVE $/ProjectD
ECHO **************************                       
ECHO       COMPLETED 
ECHO  YOUR CHECKED OUT FILES
ECHO          ARE           
ECHO    NOT OVERWRITTEN  
ECHO **************************

PAUSE

Copy the above lines of code, create a file with .bat extension and paste in it. Simple things makes your life easier.

September 30, 2010 Posted by | TFS | 5 Comments

Automated deployment build

When you create a new build definition in tfs, you will get a .proj file created. You need to make few changes to deploy your application to the destination server automatically. Here is a sample .proj file, which deploy and make changes in the web.config automatically,

<?xml version=”1.0″ encoding=”utf-8″?>
<!– DO NOT EDIT the project element – the ToolsVersion specified here does not prevent the solutions
     and projects in the SolutionToBuild item group from targeting other versions of the .NET framework.
     –>
<Project DefaultTargets=”DesktopBuild” xmlns=”http://schemas.microsoft.com/developer/msbuild/2003” ToolsVersion=”3.5″>
 
  <!– Do not edit this –>
  <Import Project=”$(MSBuildExtensionsPath)\Microsoft\VisualStudio\TeamBuild\Microsoft.TeamFoundation.Build.targets” />
  <Import Project=”$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets”/>
 
  <ProjectExtensions>
 
    <!– Team Foundation Build Version – DO NOT CHANGE –>
    <ProjectFileVersion>2</ProjectFileVersion>
 
    <!–  DESCRIPTION
     This property is included only for backwards compatibility. The description of a build definition
     is now stored in the database. For compatibility with V1 clients, keep this property in sync with
     the value in the database.
    –>
    <Description></Description>
 
    <!–  BUILD MACHINE
     This property is included only for backwards compatibility. The default machine used for a build
     definition is now stored in the database, as the MachineName property of the definition’s
     DefaultBuildAgent. For compatibility with V1 clients, keep this property in sync with the value
     in the database.
    –>
    <BuildMachine>ABC1234</BuildMachine>
 
  </ProjectExtensions>
 
  <PropertyGroup>
 
 
   <MyProjInstallDirectory>\\ABC1122\E$\Inetpub\wwwroot\MyProjName</MyProjInstallDirectory>
 
   …………..
   …………..

  </PropertyGroup>
 
  <ItemGroup>
 
    <MyProjectApplicationFiles Include=”D:\Builds\$(BuildDefinitionId)\Binaries\Release\_PublishedWebsites\MyProj.UI\**\*.*”/>
 
   …
   …

   <SolutionToBuild Include=”$(BuildProjectFolderPath)/../../../../Prod/MyProject/MyProj.sln”>
      <Targets></Targets>
      <Properties></Properties>
    </SolutionToBuild>
 
  </ItemGroup>
 
 ….
 ….
 
  </PropertyGroup>
 
  <ItemGroup>
    <!–  ADDITIONAL REFERENCE PATH
     The list of additional reference paths to use while resolving references. For example:
    
         <AdditionalReferencePath Include=”C:\MyFolder\” />
         <AdditionalReferencePath Include=”C:\MyFolder2\” />
    –>
  </ItemGroup>
 
  <Target Name=”AfterTest”>
 
    <Message Text=”Updating Web.config” />
 
   
    <XmlUpdate
       Namespace=””
       XmlFileName=”D:\builds\$(BuildDefinitionId)\Binaries\Release\_PublishedWebsites\MyProject\MyProj.WebUI\Web.Config”
       Xpath=”//configuration/appSettings/@file
       Value=”Web.Live.config” />
 
    <XmlUpdate
       Namespace=””
       XmlFileName=”D:\builds\$(BuildDefinitionId)\Binaries\Release\_PublishedWebsites\MyProject\MyProj.WebUI\Web.Config”
       Xpath=”//configuration/system.web/compilation/@debug
       Value=”false” />
 
    <Message Text=”Copying source files to live” />
 
    <Copy SourceFiles=”@(MyProjectApplicationFiles)” OverwriteReadOnlyFiles=”true” DestinationFolder =”$(MyProjInstallDirectory)\%(RecursiveDir)” />
 
 
  </Target>
 
</Project>

September 28, 2010 Posted by | TFS | Leave a comment