If you need to register and unregister NCover as part of your build process you can easily use the provided NCover.Registration.exe provided by the NCover installation.

Here's a snippet of a build file:

 <BuildRoot>$(MSBuildThisFileDirectory)</BuildRoot>  
 <BuildToolsDir>$(BuildRoot)\BuildTools</BuildToolsDir>  
 <BuildSolutionDir>$(BuildRoot)\Src</BuildSolutionDir>  
   
 <NCoverRootDir>$(BuildToolsdir)\NCover</NCoverRootDir>  
 <NCoverConsoleExe>$(NCoverRootDir)\NCover.Console.exe</NCoverConsoleExe>  
 <NCoverRegistrationExe>$(NCoverRootDir)\NCover.Registration.exe</NCoverRegistrationExe>  
 <NCoverMSBuildTaskAssembly>$(NCoverRootDir)\BuildTaskPlugins\NCover.MSBuildTasks.dll</NCoverMSBuildTaskAssembly>  
   
 <TestMSTestExe>$(VS100COMNTOOLS)\..\IDE\MSTest.exe</TestMSTestExe  
 <TestResultsDir>$(BuildRoot)TestResults</TestResultsDir>  
   
 <UsingTask TaskName="NCover.MSBuildTasks.NCover" AssemblyFile="$(NCoverMSBuildTaskAssembly)"/>  
   
 <Target Name="TestNCoverRegister">  
           <Exec Command="&quot;$(NCoverRegistrationExe)&quot; //license [KEY]"/>       
 </Target>  
        
 <Target Name="TestNCoverUnRegister">  
           <Exec Command="&quot;$(NCoverRegistrationExe)&quot; //deactivate"/>  
 </Target>  
        
 <Target Name="TestUnitsNCover" DependsOnTargets="Prepare">  
           <MsBuild Projects="$(MSBuildProjectFile)" Targets="TestNCoverRegister" Properties="ForceExecute=1"/>       
           <Delete Files="$(TestResultsDir)\UnitTests.trx" />  
           <NCover  
                     BuildId="$(BuildNumber)"  
                     ToolPath="$(NCoverRootDir)"  
                     TestRunnerExe="$(TestMSTestExe)"  
                     TestRunnerArgs="/testcontainer:&quot;$(BuildDir)\MYAPP.UnitTests.dll&quot; /resultsfile:&quot;$(TestResultsDir)\UnitTests.trx&quot; /runconfig:&quot;$(BuildSolutionDir)\LocalTestRun.testrunconfig&quot;"  
                     CoverageFile="$(TestResultsDir)\UnitTestCoverage.nccov"  
           />  
           <MsBuild Projects="$(MSBuildProjectFile)" Targets="TestNCoverUnRegister" Properties="ForceExecute=1"/>  
 </Target>  

Some notes about this build:

  • NCover is not installed in the Program Files directory, I like to keep all files required for a solution as part of the source so all of my "tools" are kept in \BuildTools.  This way if a new developer checks out the solution root they don't need to install any additional software (apart from the core things like VS and SQL Server etc)
  • You'll notice I'm not using Call task or DependsOnTargets to run the register/unregister targets, I'm using the MsBuild target to call the same build file in order to execute the same MSbuild target twice.  The reason I do this is because I have another integration test target that dopes the same thing as the unit tests but on a different DLL, so I want to be able to call the targets individually or together as part of a commit build 


Posted in: Continuous Integration , MSBuild  Tags:

Today I needed to use the TFS API to get the last successful green build info from TFS so I thought whilst I'm still learning PowerShell I'll give it a go in that.  Anyway here's what I came up with, I could have condensed the lines but whilst I was debugging in PowerShellGUI (which is REALLY good for PowerShell development!) I wanted to see what each method returned.

 

 [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")  
 [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")  
 [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Common")  
   
 $tfsCollectionUrl = "http://SERVERNAME:8080/tfs/COLLECTION"
 $server = new-object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection(New-Object Uri($tfsCollectionUrl))
 $buildServer = $server.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
 $buildDetail = $buildServer.QueryBuilds("TEAM_PROJECT", "BUILD_DEFINITION_NAME") | where { $_.BuildDefinition.LastGoodBuildUri -eq $_.Uri } #| select BuildNumber
   

$buildDetail will contain an IBuildDetail object as described here: http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.build.client.ibuilddetail.aspx

 


Posted in: PowerShell , TFS , MSBuild  Tags:

Calendar

«  May 2012  »
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910
View posts in large calendar

Recent Comments

Banners

Theme Grabber
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2012 Dan Gibbons .Net Developer