But it works on my PC!

The random thoughts of Richard Fennell on technology and software development

Using my Typemock TMockRunner Custom Activity for Team Build 2010

[Also see http://blogs.blackmarble.co.uk/blogs/rfennell/archive/2010/08/13/how-to-edit-a-tfs-2010-build-template-when-it-contains-custom-activities.aspx ]

A couple of months ago I wrote and published a custom activity for Team Build 2010 to allow Typemock tests to be run within the build process. Whilst setting up a new build need to use this activity so I though I would see if there was an easier way to use it in a build without all the branch and fuss required for development.

This is what I had to do

  • Get the Zip file what contains all the source and binaries for the custom activity
  • In your Team Project’s Source Control Explorer go to the BuildProcessTemplates folder. You should see (at least) the three standard templates: Default, Upgrade and Lab. Add the TypemockBuildProcessTemplate.xaml template from the \Source\TypemockBuildActivity folder in the zip to the BuildProcessTemplates folder
  • Under the BuildProcessTemplates folder create Custom Activities folder and into this add the TypemockBuildActivity.dll file from the root of the zip
  • Check it all these added files
  • On your Build Controller (login to the build PC and open the Team System Administration console) set its custom assemblies path to point to the folder where the custom activity DLL is stored


image 

  •  

    • You can now edit an existing build, or create a new build, to make use of the new template. You should see the new template in the list of templates, if not just use the new template option then browser to find an existing template. It is up to you of you wish to use the original or make a copy
    • As the template takes the same options as the default template it can be used as direct replacement
    • AND THIS IS WHERE YOU HIT A PROBLEM
    • The process template in the zip has parameters set for the custom activity that were correct for the test harness used for development and the source control system it was mean to upload results to. Even for me, working on the same network, these are wrong for my new project. These parameters need to be edited.
    • Usually editing would be be done using the graphical build editing tool in Visual Studio. However as detailed in my original post, getting the custom assembly in a location so that it is correctly registered with Visual Studio involves some messy branching, and if this is not done you get error block in the graphical editor.
    • There is only one way I know how to avoid this and that is to do the editing in a text editor. The parameters that needed editing for me were
      • ProjectCollection – needs to point to the right TPC
      • TestRunnerExecutable – the location of the Typemock TMOCKRunner program as different on a 32bit PC to a 64bit build machine
    • You may need to edit more, but it is easy to see what is wrong if you try a build and look at the build log, all the parameters passed on the command line are listed, as well as any error messages.
    • Once I had completed my edits I checked the edited build template back into TFS
    • I had one further problem and that was MSTEST reported in the log that it could not run due to a missing /Platform parameter. The custom activity did not pass this parameter to MSTEST as in a default 2010 build it is not set. Once I explicitly set this my build (as shown below) it built, tests ran and results were published

    image

     

  • Hope this post makes adoption of the activity a little easier for you

    TF246062: Two or more database are in conflict when upgrading to TFS 2010

    Whist upgrading a TFS2010 Beta2 server to RTM I saw the following error when I ran the verify step of the upgrade.

    TF246062: Two or more databases are in conflict because they are each designated as the owners of the following schema: Framework. The schema is for the host with the following name and ID: CollectionName, 8aace481-2471-49c8-da74-77ee3da4ce29. The databases with this conflict are: Data Source=SQLInstance1;Initial Catalog=Tfs_CollectionName;Integrated Security=True, Data Source=SQLInstance1;Initial Catalog=Tfs_Production_CollectionName;Integrated Security=True. You must specify one and only one database owner for the schema in the searchable SQL Server instances for this deployment of Team Foundation Server.

    This error is caused because you have two Team Project Collection (TPC) DBs with the same unique GUID. So how can this happen and where do these GUIDs come from?.

    When you create a TPC it gets a GUID. It keeps this GUID if you disconnect it from a TFS server and move it to another server. The only time this GUID can change is if you clone the TPC. When the cloned TPC DB is attached, the TFS spots it is a clone of a TPC is already hosts and issues a new GUID.

    So how did I get two DBs with the same GUID? The answer is that prior to the upgrade some tests had been done using another TFS server to see if the client wished to do an in-place upgrade or disaster recovery style one onto new hardware. When doing a DR style upgrade the server does not issue a new GUID, as the TPC is unique to the new server, this server knows nothing of the original TFS server. This meant, as the two server shared a SQL cluster, that we had two copies of the same DB (but with different names) on the same SQL instance, so when the TFS upgrade program asked for the DBs by GUID it got back two DBs, hence the error.

    The fix was to delete the Db created during the previous tests.

    Note: You can see a similar effect if for any reason you replicate any of the TFS Dbs on a single SQL instance, such as to make a second copy of the warehouse DB for some special reporting purpose.

    How little do you have to do to run a VS/TFS2008 build on a TFS2010 server?

    As do many people I have a good number of TFS2008 style builds for legacy applications. I will, in the end, move these over to VS2010 and hence upgrade their build formats to the new 2010 workflow based one, but for now it would be nice to be able to run them with the minimum of effort. To this end I have done some work to see the minimum I can get away with to allow these builds to run, the aim being to leave the build box as close to a virgin TFS2010 one as possible.

    Basic Setup
    My basic build system was

    • Windows Server 2008 32bit with SP2
    • TFS 2010 build

    A VS2010 Test
    Just to make sure all was OK, I created a basic VS2010 MVC2 project with it’s default tests. I then create a default build for this. This failed as my build machine did not have the targets to build a web application. I copied the directory

    C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications

    up from a development PC to the build box and tried again. The build still failed as it was missing MVC2 assemblies, I downloaded the AspNetMVC2_VS2008.exe installer to get these assemblies on my build box. Once this was all done the build worked and the tests passed

    A VS2008 Test
    So I knew I had a 2010 build system that could build and test a 2010 solution. I next took an existing VS2008 solution’s build, this build had been upgraded as part of the TFS2008->2010 server upgrade. The build failed completely. This was not surprising as as well as being for a different version of VS I knew that was missing a number of custom build tasks.

    First I had to install all the custom tasks, for me this was

    Once all these imports were present the build tried to compile, and failed with the error.

    C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets(133,11): error MSB4064: The "Retries" parameter is not supported by the "Copy" task. Verify the parameter exists on the task, and it is a settable public instance property.
    C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets(131,5): error MSB4063: The "Copy" task could not be initialized with its input parameters.  [c:\builds\Moorcroft Website\Debt Collection

    I spent a lot of time fiddling here, if I replaced my

    C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets

    with one form my PCs V9.0 directory all was OK, but then I found this post that sugested to just removed the offending parameters in the targets file, they are just retry and timouts! Once I did this the build attempted to compile the solution (and I checked it still worked for my VS2010 MVC2 solution).

    I now got another set of missing assemblies errors. This was due to the lack of MVC1 on the build box, this was downloaded and installed

    So now my MVC1 web site built, but the associated test project failed. This was because the V9 of Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll could not be found, the build box had V10. To address this I changed the assembly reference in the test project from the GAC to a copy of the assembly I included under source control, so it could be pulled to the build server.

    Everything now built. However the tests did not run. There was an error that MStest could not be found. I edited the tfsbuild.proj to add the path to the MSTest file

    PropertyGroup>
        <!-- TEST ARGUMENTS
         If the RunTest property is set to true, then particular tests within a
         metadata file or test container may be specified here.  This is
         equivalent to the /test switch on mstest.exe.

         <TestNames>BVT;HighPriority</TestNames>
        -->
        <TestToolsTaskToolPath>C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE</TestToolsTaskToolPath>
      </PropertyGroup>

    If I looked at the build log I could see that MSTest now ran, and I could see all my 100+ test, but they all failed and were not published to the TFS server. I copied the .TRX results file local from the build box and opened it in VS2010. I could then see that all the test failed because the Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll could not be seen. I am not sure it is great solution but I just dropped a copy into the same directory as MSTest.exe C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE. The other option I could think of would be to put it in the GAC.

    Once this was done most of the test executed and passed Ok, but some still did not. Again checking the .TRX file, as it still did not publish the results, was due to problems with TestContext. It seems the V9 assembly passes TestContext parameters in a different way to the V10 one. The test that passed did not have any TestContext declared. So as I did not need TestContext for these tests I just commented them out.

    All my test now ran, past, and the results were publish. The problem was if a test failed the results were not published, but this seems to be a know issue so nothing I can do about that now.

    So I now have build that mostly work, probably well enough for now. I have not need to install VS2008 or VS2010 on the build box which is nice. Just have to see how well the build holds up in production.

    TF31002: Altering the URL that your TFS 2010 Web Client uses to talk to the AT

    The Web Client for TFS 2010 (what was called Team System Web Access TSWA) is now installed as a core part of the Application Tier. It is no longer a separate install as it was in previous versions. This means it is easy to implement, it is just there by default. However, this can raise some problems if intend to expose to TFS AT via a firewall to the Internet, or use an alias for your TFS AT. This is because, by default, the Web Client uses it’s host server name as the AT name to connect to, it assumes the AT is local.

    So for example, if you install your AT on SERVER1 you can set the server so that it responds to calls to the name TFS.DOMAIN.COM (after suitable DNS registration and disabling of local loopback checks on the server). So all your TFS clients should be able to access the server via http://tfs.domain.com:8080/tfs. However if a user tried to access the sever via Web Client URL of http://tfs.domain.com:8080/tfs/web they will get an error that that the inferred local AT (http://server1:8080/tfs) cannot be resolved (from where they are outside the firewall.

    image

    TF31002: Unable to connect to this Team Foundation Server: https://server1/tfs. Team Foundation Server Url: https://server1/tfs. Possible reasons for failure include: - The name, port number, or protocol for the Team Foundation Server is incorrect. - The Team Foundation Server is offline. - The password has expired or is incorrect. Technical information (for administrator): The request failed with HTTP status 404: Not Found.

    This is easily addressed edit the C:\Program Files\Microsoft Team Foundation Server 2010\Application Tier\Web Access\Web\web.config file and explicitly name the AT to be used for the web client. This is in the block

    <tfServers>
         <!-- <add name="
    http://server:8080" /> -->
    </tfServers>

    Note here the sample URL is wrong, when you are done it should look something like

    <tfServers>  
      <add name=
    http://server1:8080/tfs /> -
    </tfServers>

    Interestingly this fixes the issue on the screen shot above for the lower instance of the error, but not, the upper one. However that is enough to get you into the client and you don’t see the error after that.

    Today’s DDD South West

    Thanks to everyone who turned up for my session at DDD South West, and to the organisers for putting the event on so well.

    As my session was basically a 1 hour demo of the testing tools in VS2010 there are no slides for me to upload, but if you have any questions ping me an email. I would say that for a good overview of the subject have a look at the book ‘Professional Application Lifecycle Management with Visual Studio 2010: with Team Foundation Server 2010

    TF50609 error when creating a new team project in TFS 2010

    After upgrading a TFS 2010 RC server (which was previously upgraded from Beta1 to Beta2) to RTM I hit a problem when trying to create a new team project. The error I saw was

    Event Description: TF30162: Task "GroupCreation1" from Group "Groups" failed
    Exception Type: Microsoft.TeamFoundation.Client.PcwException
    Exception Message: TF50609: Unable to retrieve information for action ADMINISTER_TEST_ENVIRONMENTS, it does not exist.

    A quick search shows this is a known problem with TFS 2010 Beta 1 to Beta 2 upgrades, strange it did not show itself on our servers until we when to RTM. Grant Holiday provides the solution for Beta 1 to Beta 2, but the command line required for RTM is slightly different to the one he had to use. The fix involves using both the parts of this post, the TF50660 is a symptom of the underling TF237091 error

    • Make sure you have exported a good working process template from another TPC
    • Delete all the old (Beta 2 process templates) from problem TPC
    • ALSO delete the new RTM process templates, in my case MSF Agile V5 (if you don’t do this and then reload the template the witadmin edit seems to have no effect)
    • Run the witadmin command (note no /P: option that Grant mentions and it is dimension not dim at the end)

    witadmin chnagefield /collection:http://myserver:8080/tfs/myprojectcollection /n:Microsoft.VSTS.TCM.AutomationStatus /reportingtype:dimension

    • Import the known good process template (if you had tried to do this before the witadmin edit you would have got the error ‘TF237091: Actual reporting settings for the field Microsoft.VSTS.TCM.AutomationStatus are different from those specified in the XML. Changing these settings is prohibited.’
    • You should now be able to create new team projects
    • You need to repeat this for each TPC you have that shows the problem